-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct states of operation in Table of Implemented Operations
* Add new script bin/update_stats.sh to update README automatically * New script bin/gen_stats.sh which was part of bin/compile.sh * Operation may in y, x or ~ state * Correct states of operations by providing them in the original source
- Loading branch information
Showing
14 changed files
with
227 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Purpose : Generate the table of implemented operations | ||
# Author : Ky-Anh Huynh | ||
# License : MIT | ||
# Origin : ./bin/compile.sh | ||
|
||
# <DRY_ME_PLEASE> | ||
: "${PACAPT_STATS:=yes}" # List implemented operations to STDERR | ||
: "${GREP:=grep}" # Need to update on SunOS | ||
: "${AWK:=awk}" # Need to update on SunOS | ||
|
||
# At compile time, `_sun_tools_init` is not yet defined. | ||
if [[ -f "lib/sun_tools.sh" ]]; then | ||
source "lib/sun_tools.sh" : | ||
_sun_tools_init | ||
fi | ||
|
||
export GREP AWK VERSION PACAPT_STATS | ||
# </DRY_ME_PLEASE> | ||
|
||
# $1: | ||
_implState() { | ||
if grep -qs "# ${1} _not_implemented" ./lib/*.sh; then | ||
echo "x" | ||
elif grep -qs "# ${1} may _not_implemented" ./lib/*.sh; then | ||
echo "~" | ||
else | ||
echo "y" | ||
fi | ||
} | ||
|
||
printf >&2 ":: $0: Generating statistics (table of implemented operations)..." | ||
|
||
# Operations (FQDN) | ||
_OPERATIONS=() | ||
for L in ./lib/*.sh; do | ||
_PKGNAME="${L##*/}" | ||
_PKGNAME="${_PKGNAME%.*}" | ||
|
||
case "$_PKGNAME" in | ||
"zz_main"|"00_core") continue ;; | ||
esac | ||
|
||
while read F; do | ||
_OPERATIONS+=( "$F" ) | ||
done < \ | ||
<( | ||
$GREP -hE "^${_PKGNAME}_[^ \t]+\(\)" "$L" \ | ||
| $AWK -F '(' '{print $1}' | ||
) | ||
done | ||
|
||
# Secondary options | ||
_SOPERATIONS="$( | ||
echo "${_OPERATIONS[@]}" \ | ||
| sed -e 's# #\n#g' \ | ||
| sed -e 's#^.*_\([A-Z][a-z]*\)#\1#g' \ | ||
| sort -u | ||
)" | ||
|
||
printf "\n" | ||
printf "\`\`\`\n" | ||
|
||
# Print the headers | ||
_ret="$(printf "%9s " "")" | ||
for _sopt in $_SOPERATIONS; do | ||
_size="$(( ${#_sopt} + 1))" | ||
_ret="$(printf "%s%${_size}s" "$_ret" "$_sopt")" | ||
done | ||
printf "%s\n" "$_ret" | ||
|
||
i=0 # index | ||
rs=0 # restart | ||
|
||
_OPERATIONS+=( "xxx_yyy" ) | ||
|
||
while :; do | ||
_ret="" | ||
|
||
[[ "$i" -lt "${#_OPERATIONS[@]}" ]] \ | ||
|| break | ||
|
||
_cur_pkg="${_OPERATIONS[$i]}" | ||
_cur_pkg="${_cur_pkg%_*}" | ||
|
||
for _sopt in $_SOPERATIONS; do | ||
# Detect flag for this secondary option | ||
_flag="." | ||
|
||
# Start from the #rs index, | ||
# go to boundary of the next package name. | ||
# xx_Qi, xx_Qs,... yy_Qi, yy_Qs,... | ||
# | ||
i=$rs | ||
while [[ "$i" -lt "${#_OPERATIONS[@]}" ]]; do | ||
_opt="${_OPERATIONS[$i]}" | ||
|
||
_cur2_opt="${_opt##*_}" | ||
_cur2_pkg="${_opt%_*}" | ||
|
||
# echo >&2 "(cur_pkg = $_cur_pkg, look up $_sopt [from $rs], found $_cur2_opt)" | ||
|
||
# Reach the boundary of the next package name | ||
if [[ "$_cur2_pkg" != "$_cur_pkg" ]]; then | ||
break | ||
else | ||
if [[ "$_cur2_opt" == "$_sopt" ]]; then | ||
# detect real state of this operation... | ||
_flag="$(_implState "$_opt")" | ||
break | ||
else | ||
(( i ++ )) ||: | ||
fi | ||
fi | ||
done | ||
|
||
_size="$(( ${#_sopt} + 1))" | ||
_ret="$(printf "%s%${_size}s" "$_ret" "$_flag")" | ||
done | ||
|
||
# Detect the next #restart index | ||
i=$rs | ||
while [[ "$i" -lt "${#_OPERATIONS[@]}" ]]; do | ||
_opt="${_OPERATIONS[$i]}" | ||
_cur2_pkg="${_opt%_*}" | ||
|
||
if [[ "$_cur2_pkg" != "$_cur_pkg" ]]; then | ||
rs=$i | ||
break | ||
fi | ||
|
||
(( i ++ )) ||: | ||
done | ||
|
||
if [[ "$_cur_pkg" != "xxx" ]]; then | ||
printf "%9s %s\n" "$_cur_pkg" "$_ret" | ||
fi | ||
done | ||
|
||
printf "\`\`\`\n" | ||
printf "\n**Notes:**\n\n" | ||
printf "* *y*: Implemented;\n" | ||
printf "* *~*: Implemented. Some options may not supported/implemented;\n" | ||
printf "* *x*: Operation is not supported by Operating system;\n" | ||
printf "* The table below is generated from source. Please don't update it manually.\n" | ||
printf "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Purpose : Update table of implemented operations in README.md | ||
# Author : Ky-Anh Huynh | ||
# License : MIT | ||
|
||
./bin/gen_stats.sh > stats.tmp | ||
|
||
< README.md awk ' | ||
BEGIN { | ||
ins = 0 | ||
} | ||
{ | ||
if ($0 ~ /## Implemented operations/) { | ||
print $0; | ||
ins = 1; | ||
} | ||
else { | ||
if ($0 ~ /##/) { | ||
print $0; | ||
ins = 0; | ||
} | ||
else if (ins == 0) { | ||
print $0; | ||
} | ||
} | ||
} | ||
' \ | ||
| sed -e '/## Implemented operations/r stats.tmp' \ | ||
> README.md.tmp | ||
|
||
mv README.md.tmp README.md | ||
git diff README.md |
Oops, something went wrong.