diff options
author | Roman Rakus <rrakus@redhat.com> | 2012-11-08 16:49:14 +0100 |
---|---|---|
committer | Roman Rakus <rrakus@redhat.com> | 2012-11-08 16:49:14 +0100 |
commit | c52f3069cb8f74f74c4c452e334145b43bc8d2ba (patch) | |
tree | 4f2e00d3d45cd125495e5fa1aabff9624d076a34 /tools | |
parent | 0f54f2cf59951fc1d11dc676aeb19a88e4008387 (diff) | |
download | openlmi-providers-c52f3069cb8f74f74c4c452e334145b43bc8d2ba.tar.gz openlmi-providers-c52f3069cb8f74f74c4c452e334145b43bc8d2ba.tar.xz openlmi-providers-c52f3069cb8f74f74c4c452e334145b43bc8d2ba.zip |
mof2wiki: Convert methods
Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/mof2wiki.sh | 102 |
1 files changed, 68 insertions, 34 deletions
diff --git a/tools/mof2wiki.sh b/tools/mof2wiki.sh index 4ddb48b..a868847 100755 --- a/tools/mof2wiki.sh +++ b/tools/mof2wiki.sh @@ -2,11 +2,22 @@ schemasurl='http://schemas.dmtf.org/wbem/cim-html/2.34.0/' -re_anyclass="^class[[:blank:]]*([[:alnum:]_]*):[[:blank:]]*([[:alnum:]_]*)" -re_property="^[[:blank:]]*([[:alnum:]_]*)[[:blank:]]*([[:alnum:]_]*)[[:blank:]]*;" -re_reference="^[[:blank:]]*([[:alnum:]_]*)[[:blank:]]*REF[[:blank:]]*([[:alnum:]_]*)[[:blank:]]*;" +re_anyclass="^class[[:blank:]]+([[:alnum:]_]+)[[:blank:]]*:[[:blank:]]*([[:alnum:]_]+)" +re_property="^[[:blank:]]*([[:alnum:]_]*)[[:blank:]]*([]^[:alnum:]_\[]*)[[:blank:]]*;" +re_reference="^[[:blank:]]*([[:alnum:]_]*)[[:blank:]]*REF[[:blank:]]*([]^[:alnum:]_\[]*)[[:blank:]]*;" re_endclass="^[[:blank:]]*}[[:blank:]]*;[[:blank:]]*" +re_method_start="^[[:blank:]]*([[:alnum:]_]+)[[:blank:]]+([[:alnum:]_]+)\(" +re_method_property="^[[:blank:]]*([[:alnum:]_]+)[[:blank:]]+([]^[:alnum:]_\[]+)[[:blank:]]*," +re_method_property_end="^[[:blank:]]*([[:alnum:]_]+)[[:blank:]]+([]^[:alnum:]_\[]+)[[:blank:]]*);" +re_method_reference='^[[:blank:]]*([[:alnum:]_]+)[[:blank:]]+REF[[:blank:]]+([]^[:alnum:]_\[]+)[[:blank:]]*,' +re_method_reference_end='^[[:blank:]]*([[:alnum:]_]+)[[:blank:]]+REF[[:blank:]]+([]^[:alnum:]_\[]+)[[:blank:]]*);' +re_method_end="[[:blank:]]*)[[:blank:]]*;[[:blank:]]*" +re_par_in_required='[[:blank:]]*\[[[:blank:]]*Required[[:blank:]]*,[[:blank:]]*IN' +re_par_out='[[:blank:]]*\[[[:blank:]]*.*OUT' +# assume if the parameter is not OUT then it's IN, but rather check if the word IN is present +re_par_in='[[:blank:]]*\[[[:blank:]]*.*IN' + usage() { printf "$0 usage: " @@ -57,6 +68,7 @@ all() echo for i in "${classes[@]}"; do props "$i" "$moffile" $subdir + methods "$i" "$moffile" $subdir echo done } @@ -96,7 +108,7 @@ props() while IFS= read line; do if (( ! $found )); then - if [[ $line =~ ^class[[:blank:]]*($classname)":"[[:blank:]]*([[:alnum:]_]*) ]]; then + if [[ $line =~ ^class[[:blank:]]+($classname)[[:blank:]]*":"[[:blank:]]*([[:alnum:]_]+) ]]; then newclass=${BASH_REMATCH[1]} derived=${BASH_REMATCH[2]} found=1 @@ -142,7 +154,6 @@ props() methods() { - die "Not implemented yet!" classname="$1" moffile="$2" if [[ $3 && $3 =~ [^/]$ ]]; then @@ -151,9 +162,11 @@ methods() subdir=$3 fi - unset methods - methods=() + unset found in_method + declare -i found=0 + declare -i in_method=0 + printf "Following methods\n" while IFS= read line; do if (( ! $found )); then if [[ $line =~ ^class[[:blank:]]*($classname)":"[[:blank:]]*([[:alnum:]_]*) ]]; then @@ -162,38 +175,59 @@ methods() found=1 fi else - # we have found the class, now show new defined methods - if [[ $line =~ $re_property ]]; then - ptype=${BASH_REMATCH[1]} - pname=${BASH_REMATCH[2]} - properties["$pname"]="$ptype" - elif [[ $line =~ $re_reference ]]; then - ptype=${BASH_REMATCH[1]} - pname=${BASH_REMATCH[2]} - references["$pname"]="$ptype" - elif [[ $line =~ $re_endclass ]]; then - break; + if ((! $in_method )); then + # we have found the class, now show new defined methods + if [[ $line =~ $re_method_start ]]; then + printf "== {{{%s}}} ==\n" "${BASH_REMATCH[2]}" + printf "||= Type =||= Data Type =||= Name =||\n" + printf "|| return || {{{%s}}} || ||\n" "${BASH_REMATCH[1]}" + in_method=1 + elif [[ $line =~ $re_endclass ]]; then + break; + fi + else + if [[ $line =~ $re_par_in_required ]]; then + printf "|| {{{IN required}}} || " + elif [[ $line =~ $re_par_out ]]; then + printf "|| OUT || " + elif [[ $line =~ $re_par_in ]]; then + printf "|| IN || " + elif [[ $line =~ $re_method_property ]]; then + printf "{{{%s}}} ||" "${BASH_REMATCH[1]}" + printf "{{{%s}}} ||\n" "${BASH_REMATCH[2]}" + elif [[ $line =~ $re_method_property_end ]]; then + printf "{{{%s}}} ||" "${BASH_REMATCH[1]}" + printf "{{{%s}}} ||\n" "${BASH_REMATCH[2]}" + in_method=0 + elif [[ $line =~ $re_method_reference ]]; then + cname="${BASH_REMATCH[1]}" + rname="${BASH_REMATCH[2]}" + if [[ "$cname" =~ ^CIM ]]; then + printf "[$schemasurl%s.html %s] || " "$cname" "$cname" + else + printf "[wiki:$subdir%s %s] || " "$cname" "$cname" + fi + printf "{{{%s}}} ||\n" "$rname" + elif [[ $line =~ $re_method_reference_end ]]; then + cname="${BASH_REMATCH[1]}" + rname="${BASH_REMATCH[2]}" + if [[ "$cname" =~ ^CIM ]]; then + printf "[$schemasurl%s.html %s] || " "$cname" "$cname" + else + printf "[wiki:$subdir%s %s] || " "$cname" "$cname" + fi + printf "{{{%s}}} ||\n" "$rname" + in_method=0 + elif [[ $line =~ $re_method_end ]]; then + in_method=0 + + fi fi fi done < "$moffile" if (( $found )); then - printf "= %s =\n" "$classname" - printf "Along with inherited properties from [$schemasurl%s.html %s], %s defines also following properties\n" "$derived" "$derived" "$classname" - printf "||= Property type =||= Property name =||\n" - for prop in "${!properties[@]}"; do - printf "|| {{{%s}}} || {{{%s}}}\n" "${properties[$prop]}" "$prop" - done - printf "Following references\n" - printf "||= Class name =||= Reference name =||\n" - for ref in "${!references[@]}"; do - cname="${references[$ref]}" - if [[ "$cname" =~ ^CIM ]]; then - printf "|| [$schemasurl%s.html %s] || {{{%s}}}\n" "$cname" "$cname" "$ref" - else - printf "|| [wiki:$subdir%s %s] || {{{%s}}}\n" "$cname" "$cname" "$ref" - fi - done + : else printf "Class %s not found in the file %s\n" >&2 "$classname" "$moffile" exit 1 |