From 8a24407152a54edba2fcd665d528af0e777f9533 Mon Sep 17 00:00:00 2001 From: Reid Date: Thu, 4 Aug 2016 13:15:47 +0200 Subject: Add an html formating tool for script docs. --- script-doc/script-doc.sh | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 script-doc/script-doc.sh (limited to 'script-doc') diff --git a/script-doc/script-doc.sh b/script-doc/script-doc.sh new file mode 100755 index 0000000..07690c9 --- /dev/null +++ b/script-doc/script-doc.sh @@ -0,0 +1,136 @@ +#!/bin/bash +# (c) Evol Online 2016 +# Author: Reid + +function html_header { + sed -i '1i \ + \ +'"$description"' \ + \ +

'"$description"'

' $output_location +} + +function html_footer { + echo "" >> $output_location +} + +function html_formating { + sed -i 's/^[-]{39,40}$/
/g' $output_location +} + +function html_href { + for fun in $functions + do + sed -i "s/'$fun'/'$fun<\/a>'/g" $output_location + done +} + +function table_content { + sed -i \ + '1i

Table of contents:

' \ + $output_location + sed -i '2i '"" $output_location +} + +function document_indexed { + function_id=0 + fun_line_to_skip=0 + current_line=2 + + echo "
" >> $output_location
+
+    while read unformatedline
+    do
+        line=`echo "$unformatedline" |
+              sed 's/\&/\&/g;s//\>/g'`
+
+        if [ ${functions_number[$function_id]} == $fun_line_to_skip ] \
+        && [ $fun_line_to_skip == $current_line ]
+        then
+            echo "$line" >> $output_location
+            fun_line_to_skip=$(($current_line+1))
+
+            if [ $(($function_id+1)) != ${#functions_number[@]} ]
+            then
+                ((function_id++))
+            fi
+        elif [ ${functions_number[$function_id]} == $current_line ]
+        then
+			anchor=`echo "$line" |
+                    tr ";(*\t" "    " |
+                    cut -d " " -f2`
+            echo \
+"Return to the table of contents
+
+
+
+
+$line" >> $output_location
+
+            if [ $(($function_id+1)) != ${#functions_number[@]} ]
+            then
+                ((function_id++))
+                fun_line_to_skip=$(($current_line+1))
+            fi
+        else
+            echo "$line" >> $output_location
+        fi
+
+        ((current_line++))
+    done < $input_location
+
+    echo "
" >> $output_location +} + +function line_number_of_functions +{ + grep -ne "^*[a-zAZ0-9_].*[);]$" < $input_location | + tr ":*" " " | + cut -d " " -f1 +} + +# Variables +description="Evol Online -- Hercules Script Commands" +herc_script_location="../../docs/server/scripts/script_commands.txt" +evol_script_location="../../docs/server/scripts/evol_script_commands.txt" +input_location="concat_file.txt" +output_location="script-doc.html" +cat $herc_script_location $evol_script_location > $input_location +functions_number=( `grep -ne "^*[a-zAZ0-9_].*[);]$" < $input_location | + tr ":*" " " | + cut -d " " -f1` ) +functions=`grep -e "^*[a-zAZ0-9_].*[);]$" < $input_location | + tr ";(*\t" " " | + cut -d " " -f2` + +# Remove the previous output file and concat both script command docs. +rm -f $output_location + +# Table of content redirecting to each functions. +document_indexed +table_content + +# Proper HTML formating. +html_header +html_footer +html_formating +html_href + +# Remove the temp concat file. +rm -f $input_location -- cgit v1.2.3-70-g09d2