2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-06 00:45:23 +00:00

[#2827] addressed comments

This commit is contained in:
Razvan Becheriu
2023-05-11 13:13:21 +03:00
parent c056162c99
commit d084261419
3 changed files with 152 additions and 83 deletions

View File

@@ -1,34 +1,46 @@
#!/bin/bash
work_file=`mktemp`
for file in `find ./ | grep -v "\.git" | grep -v "_build" | grep -v "\/man\/" | grep "\.rst\|\.json" | sort`; do
# Change directory to the root of the repository.
script_path=$(cd "$(dirname "${0}")" && pwd)
cd "${script_path}/.."
# Parse parameters.
if test ${#} -gt 0; then
files="${*}"
else
files='doc src'
fi
# Get the files.
files=$(find ${files} -type f \( -name '*.rst' -or -name '*.json' \) -and -not -path '/_build/*' -and -not -path '/man/*' | sort)
work_file=$(mktemp)
for file in $files; do
json=0
comment=0
line_num=0
echo "processing: $file"
while IFS= read line; do
while IFS= read -r line; do
line_num=$((line_num+1))
if [ $comment -eq 0 -a $json -eq 0 -a `echo "$line" | grep -e "^[A-Za-z]+\|^\s*\\\`" | wc -l` -eq 1 ]; then
if [ $comment -eq 0 -a $json -eq 0 -a $(echo "$line" | grep "^[A-Za-z]+\|^\s*\`" | wc -l) -eq 1 ]; then
# ignore line if it starts with 'A-Za-z' or spaces followed by '`'
continue
elif [ $comment -eq 0 -a `echo "$line" | grep -e "\/\*" | grep -v -e "\*\/" | wc -l` -eq 1 ]; then
elif [ $comment -eq 0 -a $(echo "$line" | grep "/\*" | grep -v "\*/" | wc -l) -eq 1 ]; then
# if the line contains /* and it does not contain */ on the same line
comment=1
echo "" >> $work_file
continue
elif [ $comment -eq 1 -a `echo "$line" | grep "\*\/" | wc -l` -eq 1 ]; then
elif [ $comment -eq 1 -a $(echo "$line" | grep "\*/" | wc -l) -eq 1 ]; then
# if the line contains */
comment=0
echo "" >> $work_file
continue
elif [ $comment -eq 0 -a $json -eq 0 -a `echo "$line" | grep "^\s*{\|^\s*\".*{" | grep -v "}" | grep -v "key\|pre" | wc -l` -eq 1 ]; then
# if this is not a commend and the line starts with spaces followed by '{' or by '"' followed by "{"
elif [ $comment -eq 0 -a $json -eq 0 -a $(echo "$line" | grep "^\s*{\|^\s*\".*{" | grep -v "}" | grep -v "key\|pre" | wc -l) -eq 1 ]; then
# if this is not a comment and the line starts with spaces followed by '{' or by '"' followed by "{"
# ignore dns config:
# key "key.four.example.com." {
# algorithm hmac-sha224;
# secret "bZEG7Ow8OgAUPfLWV3aAUQ==";
# };
# ignore detailed html:
# .. raw:: html
# .. raw:: html
# <details><summary>Expand here!</summary>
# <pre>{
# ...
@@ -36,9 +48,9 @@ for file in `find ./ | grep -v "\.git" | grep -v "_build" | grep -v "\/man\/" |
# </details><br>
json=1
# ignore any map name before top level map
line=`echo "$line" | sed "s/.*{/{/g"`
line=$(echo "$line" | sed "s/.*{/{/g")
echo "" > $work_file
elif [ $comment -eq 0 -a $json -eq 1 -a `echo "$line" | grep -e "^\s*[A-Za-z]\|^\s*\\\`" | wc -l` -eq 1 ]; then
elif [ $comment -eq 0 -a $json -eq 1 -a $(echo "$line" | grep "^\s*[A-Za-z]\|^\s*\`" | wc -l) -eq 1 ]; then
# if the line is not a comment and the line starts with spaces followed by 'A-Za-z' or followed by "`" and the parser is processing a json structure
json=0
cat $work_file | jq . > /dev/null
@@ -51,7 +63,7 @@ for file in `find ./ | grep -v "\.git" | grep -v "_build" | grep -v "\/man\/" |
fi
fi
if [ $comment -eq 0 -a $json -eq 1 ]; then
if [ `echo "$line" | grep -e "^\s*\.\.\s" | wc -l` -eq 1 ]; then
if [ $(echo "$line" | grep "^\s*\.\.\s" | wc -l) -eq 1 ]; then
echo "" >> $work_file
else
# if file is .json the following replace in line are done:
@@ -65,7 +77,7 @@ for file in `find ./ | grep -v "\.git" | grep -v "_build" | grep -v "\/man\/" |
# 8. replace ', ... ' with ' '
# 9. replace ' <DATA>' with ' "placeholder": "value"'
# 10. replace ' <DATA>' with ' "placeholder"'
if [ `echo "$file" | grep "\.json" | wc -l` -eq 0 ]; then
if [ $(echo "$file" | grep "\.json" | wc -l) -eq 0 ]; then
echo "$line" | cut -d "#" -f 1 | sed "s/\/\/ .*//g" | sed "s/<?.*?>//g" | sed "s/\[ <\([-A-Za-z0-9 ]*\)> \]/\[ \"<\1>\" \]/g" | sed "s/ <\(.*\)>:/ \"<\1>\":/g" | sed "s/: <\(.*\)>/: \"<\1>\"/g" | sed "s/ \.\.\./ \"placeholder\": \"value\"/g" | sed "s/, \.\.\. / /g" | sed "s/ <\(.*\)>/ \"placeholder\": \"value\"/g" | sed "s/ <\(.*\)>/ \"placeholder\"/g" >> $work_file
else
# if file is .rst the following replace in line are done: