Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b2b682e4 authored by hhakim's avatar hhakim
Browse files

Update gen_matlab_inline_doc_from_doxy_blocks.sh to make it work on macOS.

The script was disabled on macOS by c0ae3a3f and first added by e92d4bc6.
parent 1029faaf
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# this script takes a matlab script documented as defined by doxygen matlab plugin
# parse the doxy doc block and generate a new file .m with inline doc corresponding to the doxygen doc (filtering doxygen tags)
# parses the doxy doc block and generates a new file .m with inline doc corresponding to the doxygen doc (filtering doxygen tags)
# if a inner code comment block is already present in a function (in the start, just after its name) it will be replaced
function usage {
echo "USAGE: $0 <input_path.m> <output_path.m>"
echo "USAGE: $0 <input_path.m> <output_path.m>"
}
function usage_exit {
usage
exit $1
usage
exit $1
}
function parse_doxy_block {
local FUNC=$(echo $1 | tr '[a-z]' '[A-Z]')
local FUNC_LINE=$(echo "$3" | sed -e 's/^[[:blank:]]\+//')
echo -e "$2" | sed -e "{
s/^\s*%=\+//;
s/%>\s*@brief/%% $FUNC/;
s/^\([[:blank:]]\+\)%> @param F/\1% SPECS: $FUNC_LINE:\n\1\t% - Parameter F: /;
s/%>/%/;
s/^/\t/;
s/Usage/Usage:/
s/@param\s\([^[:blank:]]\+\)/- Parameter \1: /;
s/@code/=========== code ===========/;
s/@endcode/========= end code =========/;
s/\(Examples\?\)/\1:/
s/<[^>]*>//g;
s/&nbsp;/ /g;
s/@retval/Returns/g;
s/@[^[:blank:]]* \?//g;
s/\\\./\./g
}"
local FUNC=$(echo $1 | tr '[a-z]' '[A-Z]')
local FUNC_LINE=$(echo "$3" | sed -e 's/^[[:blank:]]\{1,\}//')
echo -e "$2" | sed -e "{
s/^[[:blank:]]*%=\{1,\}//;
s/%>[[:blank:]]*@brief/%% $FUNC/;
s/^\([[:blank:]]\{1,\}\)%> @param F/\1% SPECS: $FUNC_LINE:\n\1\t% - Parameter F: /;
s/%>/%/;
#s/^/\\t/;
s/Usage/Usage:/
s/@param[[:blank:]]\([^[:blank:]]\{1,\}\)/- Parameter \1: /;
s/@code/=========== code ===========/;
s/@endcode/========= end code =========/;
s/\(Examples\{0,1\}\)/\1:/
s/<[^>]*>//g;
s/&nbsp;/ /g;
s/@retval/Returns/g;
s/@[^[:blank:]]* \{0,1\}//g;
s/\\\./\./g
}"
}
# parse input args
......@@ -42,7 +42,7 @@ function parse_doxy_block {
[[ -z $(dirname "$2") || -d "$(dirname $2)" ]] && OUTPUT_FILE="$2" || usage_exit 2
# get function names
FUNCTIONS=$(sed -ne 's/^\s*function[[:blank:]]\+\([^=]\+=\)\?\s*\([^([:blank:]]\+\).*$/\2/p' "$INPUT_FILE")
FUNCTIONS=$(sed -ne 's/^[[:blank:]]*function[[:blank:]]\{1,\}\([^=]\{1,\}=\)\{0,1\}[[:blank:]]*\([^([:blank:]]\{1,\}\).*$/\2/p' "$INPUT_FILE")
[[ -z "${FUNCTIONS}" ]] && echo "ERROR in getting the list of functions in $INPUT_FILE" && exit 3
......@@ -51,41 +51,47 @@ cp "$INPUT_FILE" "$OUTPUT_FILE"
[ ! "$?" = 0 ] && echo "ERROR in copying file." >&2 && exit 4
DOXY_BLOCKS_LIMITS=($(sed -ne '/\s*\%=\+\s*/=' "$INPUT_FILE"))
DOXY_BLOCKS_LIMITS=($(sed -ne '/[[:blank:]]*\%=\{1,\}[[:blank:]]*/=' "$INPUT_FILE"))
typeset -i DOXY_BLOCK_ID=0
for FUNC in $FUNCTIONS
do
# get the line numbers of the current inline code block
INLINE_DOC_LINE_NUMS=($(sed -ne '/^\s*function[[:blank:]]\+\([^=]\+=\)\?\s*\('$FUNC'\)[[:blank:]]*(.*$/,/^[[:blank:]]*[^%]\+$/=' $OUTPUT_FILE))
# delete not empty inline code doc block
if [ ${#INLINE_DOC_LINE_NUMS[*]} -gt 2 ]
then
INLINE_DOC_START_NUM=${INLINE_DOC_LINE_NUMS[1]}
INLINE_DOC_END_NUM=${INLINE_DOC_LINE_NUMS[-2]}
[[ $INLINE_DOC_START_NUM =~ [[:digit:]]+ && $INLINE_DOC_END_NUM =~ [[:digit:]]+ ]] && sed -i "${INLINE_DOC_START_NUM},${INLINE_DOC_END_NUM}d" ${OUTPUT_FILE}
[ ! "$?" = 0 ] && echo "ERROR sed deleting old inline doc block." >&2 && exit 5
fi
# get the doxy block for the function
DOXY_BLOCK=$(sed -ne "$((${DOXY_BLOCKS_LIMITS[$DOXY_BLOCK_ID]}+1)),$((${DOXY_BLOCKS_LIMITS[$(($DOXY_BLOCK_ID+1))]}-1))p" "$INPUT_FILE")
[[ "$DEBUG" = "DOXY_BLOCK" ]] && echo "DOXY_BLOCK=$DOXY_BLOCK"
# get the new line position of the function
FUNC_LINE=$(sed -ne '/^\s*function[[:blank:]]\+\([^=]\+=\)\?\s*\('$FUNC'\)[[:blank:]]*(.*$/=' "$OUTPUT_FILE")
[[ "$DEBUG" = "FUNC_LINE" ]] && echo FUNC_LINE=$FUNC_LINE FUNC=$FUNC >&2
[[ ! $FUNC_LINE =~ [[:digit:]]+ ]] && echo "ERROR in getting function $FUNC line number in $OUTPUT_FILE." >&2 && DOXY_BLOCK_ID+=2 && continue
# insert parsed block
FUNC_DEF_LINE=$(sed -ne $FUNC_LINE'p' $OUTPUT_FILE)
# get the line numbers of the current inline code block
# INLINE_DOC_LINE_NUMS=($(sed -ne '/^[[:blank:]]*function[[:blank:]]\{1,\}\([^=]\{1,\}=\)\{0,1\}[[:blank:]]*\('$FUNC'\)[[:blank:]]*(.*$/,/^[[:blank:]]*[^%]\{1,\}$/=' $OUTPUT_FILE))
INLINE_DOC_START_NUM=$(sed -ne '/^[[:blank:]]*function[[:blank:]]\{1,\}\([^=]\{1,\}=\)\{0,1\}[[:blank:]]*\('$FUNC'\)[[:blank:]]*(.*$/=' $OUTPUT_FILE)
NLINES=$(($(sed -ne '/^[[:blank:]]*function[[:blank:]]\{1,\}\([^=]\{1,\}=\)\{0,1\}[[:blank:]]*\('$FUNC'\)[[:blank:]]*(.*$/,/^[[:blank:]]*[^%]\{1,\}$/p' $OUTPUT_FILE | wc -l)-1))
INLINE_DOC_END_NUM=$(($INLINE_DOC_START_NUM+$NLINES))
FILE_NLINES=$(wc -l ${OUTPUT_FILE} | awk '{print $1}')
[[ "$DEBUG" = "INLINE_DOC_BLOCK" ]] && echo "INLINE_DOC_START_NUM=$INLINE_DOC_START_NUM NLINES=$NLINES INLINE_DOC_END_NUM=$INLINE_DOC_END_NUM"
# delete not empty inline code doc block
# if [ ${#INLINE_DOC_LINE_NUMS[*]} -gt 2 ]
# then
# INLINE_DOC_START_NUM=${INLINE_DOC_LINE_NUMS[1]}
# INLINE_DOC_END_NUM=${INLINE_DOC_LINE_NUMS[-2]}
#[[ $INLINE_DOC_START_NUM =~ [[:digit:]]+ && $INLINE_DOC_END_NUM =~ [[:digit:]]+ ]] && sed -i "${INLINE_DOC_START_NUM},${INLINE_DOC_END_NUM}d" ${OUTPUT_FILE}
[[ $INLINE_DOC_START_NUM =~ [[:digit:]]+ && $INLINE_DOC_END_NUM =~ [[:digit:]]+ ]] && sed -ne "1,${INLINE_DOC_START_NUM}p;${INLINE_DOC_END_NUM},${FILE_NLINES}p" "${OUTPUT_FILE}" > tmp_${OUTPUT_FILE} && mv tmp_${OUTPUT_FILE} ${OUTPUT_FILE}
[ ! "$?" = 0 ] && echo "ERROR sed deleting old inline doc block." >&2 && exit 5
# fi
# get the doxy block for the function
DOXY_BLOCK=$(sed -ne "$((${DOXY_BLOCKS_LIMITS[$DOXY_BLOCK_ID]}+1)),$((${DOXY_BLOCKS_LIMITS[$(($DOXY_BLOCK_ID+1))]}-1))p" "$INPUT_FILE")
[[ "$DEBUG" = "DOXY_BLOCK" ]] && echo "DOXY_BLOCK=$DOXY_BLOCK"
# get the new line position of the function
FUNC_LINE=$(sed -ne '/^[[:blank:]]*function[[:blank:]]\{1,\}\([^=]\{1,\}=\)\{0,1\}[[:blank:]]*\('$FUNC'\)[[:blank:]]*(.*$/=' "$OUTPUT_FILE")
[[ "$DEBUG" = "FUNC_LINE" ]] && echo FUNC_LINE=$FUNC_LINE FUNC=$FUNC >&2
[[ ! $FUNC_LINE =~ [[:digit:]]+ ]] && echo "ERROR in getting function $FUNC line number in $OUTPUT_FILE." >&2 && DOXY_BLOCK_ID+=2 && continue
# insert parsed block
FUNC_DEF_LINE=$(sed -ne $FUNC_LINE'p' $OUTPUT_FILE)
sed -ne '1,'$FUNC_LINE'p' $OUTPUT_FILE > ${OUTPUT_FILE}_tmp
# parse doxy block for inline block
INLINE_BLOCK=$(parse_doxy_block $FUNC "$DOXY_BLOCK" "$FUNC_DEF_LINE")
echo -e "$INLINE_BLOCK" >> ${OUTPUT_FILE}_tmp
sed -ne $(($FUNC_LINE+1))','$(wc -l ${OUTPUT_FILE} | awk '{print $1}')'p' $OUTPUT_FILE >> ${OUTPUT_FILE}_tmp
[ "$?" = 0 ] && mv ${OUTPUT_FILE}_tmp ${OUTPUT_FILE}
DOXY_BLOCK_ID+=2
# parse doxy block for inline block
INLINE_BLOCK=$(parse_doxy_block $FUNC "$DOXY_BLOCK" "$FUNC_DEF_LINE")
echo -e "$INLINE_BLOCK" >> ${OUTPUT_FILE}_tmp
sed -ne $(($FUNC_LINE+1))','$(wc -l ${OUTPUT_FILE} | awk '{print $1}')'p' $OUTPUT_FILE >> ${OUTPUT_FILE}_tmp
[ "$?" = 0 ] && mv ${OUTPUT_FILE}_tmp ${OUTPUT_FILE}
DOXY_BLOCK_ID+=2
done
......@@ -97,10 +103,8 @@ DOXY_HEADER=$(sed -ne "$((${HEADER_START_END[0]}+1)),$((${HEADER_START_END[1]}-1
[[ "$DEBUG" = "DOXY_HEADER" ]] && echo "DOXY_HEADER=$DOXY_HEADER"
INLINE_HEADER=$(parse_doxy_block "FAUST" "$DOXY_HEADER")
[[ "$DEBUG" = "INLINE_HEADER" ]] && echo "INLINE_HEADER=$INLINE_HEADER"
echo -e "$INLINE_HEADER" | sed 's/^[[:blank:]]\+//' > ${OUTPUT_FILE}_tmp
echo -e "$INLINE_HEADER" | sed 's/^[[:blank:]]\{1,\}//' > ${OUTPUT_FILE}_tmp
echo -e '\n\n' >> ${OUTPUT_FILE}_tmp
sed -ne "${HEADER_START_END[0]},${OUT_NUM_LINES}p" $OUTPUT_FILE >> ${OUTPUT_FILE}_tmp
[ "$?" = 0 ] && mv ${OUTPUT_FILE}_tmp ${OUTPUT_FILE}
......@@ -15,7 +15,7 @@ endforeach()
# install Faust.m in the CMAKE_INSTALL_MATLAB_PREFIX directory
file(MAKE_DIRECTORY ${FAUST_MATLAB_MAIN_CLASS_FQDN_BIN_DIR})
if(WIN32 OR APPLE)
if(WIN32)
configure_file(${FAUST_MATLAB_MAIN_CLASS_FQDN_SRC_DIR}/Faust.m ${FAUST_MATLAB_MAIN_CLASS_FQDN_BIN_DIR}/Faust.m COPYONLY)
#install(FILES ${FAUST_MATLAB_BIN_DIR}/Faust.m DESTINATION ${CMAKE_INSTALL_MATLAB_PREFIX} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
else()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment