# SccsId[] = "%W% (USL function) %G%"
              FT_name="FRAME_TEXT"
              if [ ".${SECONDS}" = "." ]; then # Bourne function already loaded?
                 [ ."`set|egrep '^$FT_name\(\)\{$'`" != . ] && FT_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 '/^'$FT_name'[=\(]?/'`" != . ] && FT_loaded=1
                 else # Linux
                    [ ."`typeset -F|awk '/^'$FT_name'[=\(]?/'`" != . ] && FT_loaded=1
                 fi
              fi
              #if [ 0${FT_loaded} -eq 0 ]; then
              #----------------------------------------------------------------------#
              FRAME_TEXT() # 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 [ ."$1" != . ]; then
                   $AWK -v text="$1" -v len=$2 -v post=$3 -v lintel=$4 \
                     'BEGIN \
                      { # len = minimum framed text length
                        if (len    == "") len    = length(text)
                        if (post   == "") post   = "#"
                        if (lintel == "") lintel = "-"
                        fill_n = len - length(text)
                        left_n = int(fill_n / 2)
                        odd_n  =     fill_n % 2
                        right  = left = sprintf("%"left_n"s", " ")
                        if (odd_n > 0) right = left" "
                        len = length(left""text""right) + 2
                        top_n_bot = post""sprintf("%"(len-2)"s",lintel)""post
                        gsub(/ /,lintel,top_n_bot) # Change intervening blanks
                        print top_n_bot"\n"post""left""text""right""post"\n"top_n_bot
                      }'
                   return 0
                fi

                #------------------------------------------#
                # Reaching here means something is amiss.  #
                #------------------------------------------#
                if [ .${SHLIB} = . ]; then SHLIB=/usr/local/scripts; export SHLIB; fi

                . $SHLIB/email_msg.sh # Calls $SHLIB/exit.sh

                #------------------------------------------------------------#
                # If the following variables are not set, use these defaults.#
                #------------------------------------------------------------#
                : ${script_name:=`basename $0`}
                : ${sp:="                    "}

                FT_ID="FUNCTION ERR $script_name($FT_name)"

                EMAIL_MSG "ERROR (Function): $FT_ID"                       \
                  "${sp}Insufficient arg."                                 \
                  "${sp}Usage: $FT_name 'text' [posts [lintel [length]]]." \
                  "${sp}       Where text   = Quoted text to frame,"       \
                  "${sp}             length = box length (defaults to"     \
                  "${sp}                      text length + 6),"           \
                  "${sp}             posts  = box side character,"         \
                  "${sp}             lintel = top/bottom character."
                return 1
              } # "FT_" prefix identifies this function's local variables.
              #fi

              #======================================================================#
              #                       D O C U M E N T A T I O N                      #
              #======================================================================#
              #                                                                      #
              #      Author: Bob Orlando                                             #
              #                                                                      #
              #        Date: December 14, 1996                                       #
              #                                                                      #
              #  Program ID: frame_text.sh                                           #
              #                                                                      #
              #       Usage: FRAME_TEXT    "text" [[[length] post] lintel]           #
              #                                                                      #
              #     Purpose: Frame a text string ($1) using using default posts      #
              #              and lintel (optional args $3 and $4) for an optionally  #
              #              specified length ($2).  If none of the optional         #
              #              parameters are supplied, then the text is framed to     #
              #              a text-length + 6 (including the posts).                #
              #                                                                      #
              #     Globals: No global variables assigned from this function.        #
              #              "FT_" prefix identifies local function variables.       #
              #                                                                      #
              # Exit_status: Returns with failure (1) on error (e.g. user supplies   #
              #              invalid arguments).  Else returns success (0), echoing  #
              #              the framed text to stdout.                              #
              #                                                                      #
              #       Calls: EMAIL_MSG library function.                             #
              #                                                                      #
              #       Notes: Outputs to stdout (user modifies/redirects as           #
              #              needed).  For example, the following command            #
              #                                                                      #
              #                  FRAME_TEXT "$mm/$dd/$yyyy" 10 \                     #
              #                    | sed "s/^/$sp/" | $teelog                        #
              #                                                                      #
              #                                #------------------#                  #
              #              might produce ..  #    01/22/1997    #                  #
              #                                #------------------#                  #
              #                                                                      #
              #    Modified: 20yy-mm-dd Bob Orlando                                  #
              #                 v1.9  * Replace for loop with sprintf and gsub.      #
              #                                                                      #
              #----------------------------------------------------------------------#
            
Artificial Intelligence is no match for natural stupidity.
©Copyright Bob Orlando, 1996-2011
All rights reserved.
http://www.OrlandoKuntao.com
E-mail: Bob@OrlandoKuntao.com
Last update: Jan. 26, 2011
by Bob Orlando