# SccsId[] = "%W% (USL function) %G%"
              SD_name="SHOW_DOCUMENTATION"
              if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
                 [ ."`set|egrep '^$SD_name\(\)\{$'`" != . ] && SD_loaded=1
              else # Korn or Bash shell and function already loaded?
                 if [ `expr "\`uname -s\`" : "[Ll][Ii][Nn][Uu][Xx]"` -eq 0 ]; then
                    [ ."`typeset +f|awk '/^'$SD_name'[=\(]?/'`" != . ] && SD_loaded=1
                 else # Linux
                    [ ."`typeset -F|awk '/^'$SD_name'[=\(]?/'`" != . ] && SD_loaded=1
                 fi
              fi
              if [ 0${SD_loaded} -eq 0 ]; then
              #----------------------------------------------------------------------#
              SHOW_DOCUMENTATION() # Function documentation located at bottom.       #
              #----------------------------------------------------------------------#
              { [ ."${AWK}" = . ] && { { [ -x /usr/bin/nawk ] && AWK=/usr/bin/nawk; } \
                                  ||   { [ -x /bin/gawk     ] && AWK=/bin/gawk    ; } \
                                  ||   { [ -x /usr/bin/awk  ] && AWK=/usr/bin/awk ; }; }

                #----------------------------------------------------------------#
                # If the following variables are not set, use these as defaults. #
                #----------------------------------------------------------------#
                : ${sp:="                    "} # 20 spaces
                : ${script_name:=`basename $0`}
                : ${script_home:=`dirname  $0`}
                SD_script_home=`echo $script_home|sed 's/\/*$/\//'`

                #----------------------------------------------#
                # User wants help, so find the documentation   #
                # section and print everything from there down.#
                #----------------------------------------------#
                $AWK -v script_name=$script_name -v sp="$sp" \
                  'BEGIN { n=0 }
                   { # Examine each line until we find the documentation section.
                     if (n == 0)
                     {
                       if ($0 ~ /^# +D O C U M E N T A T I O N/)
                       {
                         n = NR
                         print line
                         print $0
                       }
                       else
                         line = $0

                       next
                     }
                     else # Once we find it, print until EOF.
                       print
                   }
                   END \
                   {
                     if (n == 0) # Means we found no documentation section.
                     {
                       print sp"NO DOCUMENTATION",
                         "section found for "script_name"." | "cat 1>&2"
                       exit 1 # Exit failure
                     }
                     exit 0 # Else exit success
                   }' ${SD_script_home}$script_name

                [ ."$1" = ."-x" ] && exit $? || return $?
              } # "SD_" prefix identifies this function's variables
              fi

              #======================================================================#
              #                       D O C U M E N T A T I O N                      #
              #======================================================================#
              #                                                                      #
              #      Author: Bob Orlando                                             #
              #                                                                      #
              #        Date: January 14, 1997                                        #
              #                                                                      #
              #  Program ID: show_documentation.sh                                   #
              #                                                                      #
              #       Usage: SHOW_DOCUMENTATION -x                                   #
              #                           Where -x says we're to exit after          #
              #                                    displaying documentation.         #
              #                                                                      #
              #     Purpose: Display formal documentation section of the calling     #
              #              script.                                                 #
              #                                                                      #
              # Description: This function looks for a "D O C U M E N T A T I O N"   #
              #              line in the calling script (like the one above).  If    #
              #              one is found, everything from that line (minus one--    #
              #              the line above it) is displayed to stdout.  It is       #
              #              up to the user to pipe it through "more" as needed.     #
              #                                                                      #
              #     Globals: No global variables are assigned in this function.      #
              #              "SD_" prefix identifies local function variables.       #
              #                                                                      #
              # Exit_status: Success or failure (0 or 1).  If failure, an error      #
              #              indicating that the script has no documentation         #
              #              is displayed.                                           #
              #                                                                      #
              #       Calls: None.                                                   #
              #                                                                      #
              #       Notes: .....................................................   #
              #              .....................................................   #
              #                                                                      #
              #    Modified: 2004-04-02 Bob Orlando                                  #
              #                 v1.8  * Expand $AWK testing and assignment.          #
              #                                                                      #
              #              2004-03-03 Bob Orlando                                  #
              #                 v1.7  * Change set|egrep|awk to just set|egrep.      #
              #                                                                      #
              #----------------------------------------------------------------------#
            
Artificial Intelligence is no match for natural stupidity.
©Copyright Bob Orlando, 1997-2011
All rights reserved.
http://www.OrlandoKuntao.com
E-mail: Bob@OrlandoKuntao.com
Last update: Jan. 26, 2011
by Bob Orlando