      *>----------------------------------------------------------
      *> The MessageFileHandler class will register National
      *> Language files, allowing messages to be retrieved from
      *> them.
      *>
      *> Copyright (C) 1995-1998 Micro Focus International Ltd.
      *>
      *>----------------------------------------------------------
      $set mfoo ooctrl(+n) localCount(255) linkCount(255) nls
       class-id. MessageFileHandler data is protected
                 inherits from Base with data.


       object section.
       class-control.
           Base is class "base"
           MessageFileHandler is class "msgfh"
           CharacterArray is class "chararry"
           .

       class-object.
       object-storage section.
      *>----------------------------------------------------------------
      *> Create and return an instance (lnkNewObject) of the
      *> MessageFileHandler class, by specifying the logical language
      *> library name (lnkLanguageLibrary (see below) and the language
      *> filename (lnkLanguageFilename).
      *>
      *> The logical language library name can be any National Language
      *> library, without the suffixed two-digit language code that is
      *> used to determine which message catalog is opened.
      *>
      *> For additonal information, refer to the "National Language
      *> Support (NLS)" chapter in the documentation.
      *>----------------------------------------------------------------

       method-id. "registerMessageFile".

       linkage section.
       01 lnkLanguageLibrary       usage object reference.
       01 lnkLanguageFilename      usage object reference.
       01 lnkNewObject             usage object reference.

       procedure division using lnkLanguageLibrary
                                lnkLanguageFilename
                      returning lnkNewObject.
           invoke super "new"
                       returning lnkNewObject
           invoke lnkNewObject "setLanguageLibrary"
                           using lnkLanguageLibrary
           invoke lnkNewObject "setLanguageFilename"
                           using lnkLanguageFilename
           exit method.
       end method "registerMessageFile".
      *>----------------------------------------------------------------
      *> Create and return an instance (lnkNewObject) of the
      *> MessageFileHandler class, by specifying the logical language
      *> library name string (lnkLanguageLibraryString (see
      *> below) and the language filename string
      *> (lnkLanguageFilename). Both strings must be terminated
      *> with a null character.
      *>
      *> The logical language library name can be any National Language
      *> library, without the suffixed two-digit language code that is
      *> used to determine which message catalog is opened.
      *>
      *> For additonal information, refer to the "National Language
      *> Support (NLS)" chapter in the documentation.
      *>----------------------------------------------------------------

       method-id. "registerMessageFileZ".

       local-storage section.
       01 lsLanguageLibrary            usage object reference.
       01 lsLanguageFilename           usage object reference.
       01 lsLibraryByteSize            pic s9(9) comp-5.
       01 lsFilenameByteSize           pic s9(9) comp-5.

       linkage section.
       01 lnkLanguageLibraryString.
          03 lnkLanguageLibraryChar    pic x occurs 0 to maxNumberBytes
                                       depending on lsLibraryByteSize.

       01 lnkLanguageFilenameString.
          03 lnkLanguageFilenameChar   pic x occurs 0 to maxNumberBytes
                                       depending on lsFilenameByteSize.

       01 lnkNewObject             usage object reference.

       procedure division using lnkLanguageLibraryString
                                lnkLanguageFilenameString
                      returning lnkNewObject.
           invoke super "new"
                       returning lnkNewObject
           invoke CharacterArray "withValue"
                           using lnkLanguageLibraryString
                       returning lsLanguageLibrary
           invoke lsLanguageLibrary "sizeInBytes"
                       returning lsLibraryByteSize
           invoke lnkNewObject "setLanguageLibrary"
                           using lsLanguageLibrary
           if lsLanguageLibrary = null
               continue
           else
               invoke lsLanguageLibrary "finalize"
                           returning lsLanguageLibrary
           end-if
           invoke CharacterArray "withValue"
                           using lnkLanguageFilenameString
                       returning lsLanguageFilename
           invoke lsLanguageFilename "sizeInBytes"
                       returning lsFilenameByteSize
           invoke lnkNewObject "setLanguageFilename"
                           using lsLanguageFilename
           if lsLanguageFilename = null
               continue
           else
               invoke lsLanguageFilename "finalize"
                           returning lsLanguageFilename
           end-if
           exit method.
       end method "registerMessageFileZ".
       end class-object.
       object.
       object-storage section.
       01 objLanguageLibrary       usage object reference.
       01 objLanguageBasename      usage object reference.
       01 objLanguageExtensionName usage object reference.
      *>----------------------------------------------------------------
      *> Set or change the language filename.
      *>----------------------------------------------------------------

       method-id. "setLanguageFilename".

       local-storage section.
       01 lsByteSize                       pic s9(9) comp-5.
       01 lsCharSize                       pic s9(9) comp-5.
       01 lsSplitJoinParameters.
          03 lsSplitJoinParameterLength    pic x(2) comp-x.
          03 lsSplitJoinFlag1              pic x comp-x.
          03 lsSplitJoinFlag2              pic x comp-x.
          03 lsDeviceOffset                pic x(2) comp-x.
          03 lsDeviceLength                pic x(2) comp-x.
          03 lsBasenameOffset              pic x(2) comp-x.
          03 lsBasenameLength              pic x(2) comp-x.
          03 lsExtensionOffset             pic x(2) comp-x.
          03 lsExtensionLength             pic x(2) comp-x.
          03 lsTotalLength                 pic x(2) comp-x.
          03 lsSplitBufferLength           pic x(2) comp-x.
          03 lsJoinBufferLength            pic x(2) comp-x.
          03 lsFirstPathComponentLength    pic x(2) comp-x.
       01 lsSplitBuffer                    pic x(266).
       01 lsStatusCode                     pic x(2) comp-5.

       linkage section.
       01 lnkLanguageFilename      usage object reference.

       procedure division using lnkLanguageFilename.

           move 24 to lsSplitJoinParameterLength
           move zero to lsSplitJoinFlag1
           move 266 to lsSplitBufferLength
           move spaces to lsSplitBuffer
           invoke lnkLanguageFilename "getValue"
                           returning lsSplitBuffer
           call "CBL_SPLIT_FILENAME"
                           using lsSplitJoinParameters
                                 lsSplitBuffer
                       returning lsStatusCode

           if objLanguageBasename = null
               continue
           else
               invoke objLanguageBasename "finalize"
                           returning objLanguageBasename
           end-if
           move lsBasenameLength to lsByteSize
           invoke CharacterArray "withByteLengthValue"
                           using lsByteSize
                                 lsSplitBuffer(lsBasenameOffset
                                              :lsBasenameLength)
                       returning objLanguageBasename

           if objLanguageExtensionName = null
               continue
           else
               invoke objLanguageExtensionName "finalize"
                           returning objLanguageExtensionName
           end-if
           if lsExtensionLength = zero
               move zero to lsCharSize
               invoke CharacterArray "new"
                               using lsCharSize
                           returning objLanguageExtensionName
           else
               if lsExtensionLength = 1
                   if lsSplitBuffer(lsExtensionOffset:1) = "."
                       invoke CharacterArray "withValue"
                                       using "." & x"00"
                                   returning objLanguageExtensionName
                   else
                       move 1 to lsCharSize
                       invoke CharacterArray "withLengthValue"
                                       using lsCharSize
                                             lsSplitBuffer(
                                               lsExtensionOffset:1)
                                   returning objLanguageExtensionName
                   end-if
               else
                   move lsExtensionLength to lsByteSize
                   invoke CharacterArray "withByteLengthValue"
                                   using lsByteSize
                                         lsSplitBuffer(lsExtensionOffset
                                                     :lsExtensionLength)
                               returning objLanguageExtensionName
               end-if
           end-if
           exit method.
       end method "setLanguageFilename".
      *>----------------------------------------------------------------
      *> Set or change the language filename using a null terminated
      *> string.
      *>----------------------------------------------------------------

       method-id. "setLanguageFilenameZ".

       local-storage section.
       01 lsLanguageFilename           usage object reference.

       linkage section.
       01 lnkLanguageFilenameString    pic x.

       procedure division using lnkLanguageFilenameString.
           invoke CharacterArray "withValue"
                           using lnkLanguageFilenameString
                       returning lsLanguageFilename
           invoke self "setLanguageFilename"
                           using lsLanguageFilename
           if lsLanguageFilename = null
               continue
           else
               invoke lsLanguageFilename "finalize"
                           returning lsLanguageFilename
           end-if
           exit method.
       end method "setLanguageFilenameZ".
      *>----------------------------------------------------------------
      *> Get the current language filename.
      *>----------------------------------------------------------------

       method-id. "getLanguageFilename".

       local-storage section.
       01 lsByteSize                       pic s9(9) comp-5.
       01 lsCharSize                       pic s9(9) comp-5.
       01 lsSplitJoinParameters.
          03 lsSplitJoinParameterLength    pic x(2) comp-x.
          03 lsSplitJoinFlag1              pic x comp-x.
          03 lsSplitJoinFlag2              pic x comp-x.
          03 lsDeviceOffset                pic x(2) comp-x.
          03 lsDeviceLength                pic x(2) comp-x.
          03 lsBasenameOffset              pic x(2) comp-x.
          03 lsBasenameLength              pic x(2) comp-x.
          03 lsExtensionOffset             pic x(2) comp-x.
          03 lsExtensionLength             pic x(2) comp-x.
          03 lsTotalLength                 pic x(2) comp-x.
          03 lsSplitBufferLength           pic x(2) comp-x.
          03 lsJoinBufferLength            pic x(2) comp-x.
          03 lsFirstPathComponentLength    pic x(2) comp-x.
       01 lsJoinBuffer                     pic x(266).
       01 lsPathBuffer                     pic x(266).
       01 lsBasenameBuffer                 pic x(266).
       01 lsExtensionBuffer                pic x(266).
       01 lsStatusCode                     pic x(2) comp-5.

       linkage section.
       01 lnkLanguageFilename      usage object reference.

       procedure division returning lnkLanguageFilename.

           move 24 to lsSplitJoinParameterLength
           move zero to lsSplitJoinFlag1
           move zero to lsSplitJoinFlag2
           move 1 to lsDeviceOffset
           move 266 to lsDeviceLength
           move 1 to lsBasenameOffset
           move 266 to lsBasenameLength
           move 1 to lsExtensionOffset
           move 266 to lsExtensionLength
           move spaces to lsPathBuffer
           move space to lsBasenameBuffer
           invoke objLanguageBasename "getValue"
                       returning lsBasenameBuffer
           move spaces to lsExtensionBuffer
           invoke objLanguageExtensionName "getValue"
                       returning lsExtensionBuffer
           move 266 to lsJoinBufferLength
           call "CBL_JOIN_FILENAME"
                           using lsSplitJoinParameters
                                 lsJoinBuffer
                                 lsPathBuffer
                                 lsBasenameBuffer
                                 lsExtensionBuffer
                       returning lsStatusCode
           move lsTotalLength to lsByteSize
           invoke CharacterArray "withByteLengthValue"
                           using lsByteSize
                                 lsJoinBuffer
                       returning lnkLanguageFilename
           exit method.
       end method "getLanguageFilename".
      *>----------------------------------------------------------------
      *> Set the logical language library name.
      *>
      *> The logical language library name can be any National Language
      *> library, without the suffixed two-digit language code that is
      *> used to determine which message catalog is opened.
      *>
      *> For additonal information, refer to the "National Language
      *> Support (NLS)" chapter in the documentation.
      *>----------------------------------------------------------------

       method-id. "setLanguageLibrary".

       linkage section.
       01 lnkLanguageLibrary       usage object reference.

       procedure division using lnkLanguageLibrary.
           if objLanguageLibrary = null
               continue
           else
               invoke objLanguageLibrary "finalize"
                           returning objLanguageLibrary
           end-if
           invoke lnkLanguageLibrary "copy"
                       returning objLanguageLibrary
           exit method.
       end method "setLanguageLibrary".
      *>----------------------------------------------------------------
      *> Set the logical language library using a null terminated
      *> string.
      *>
      *> The logical language library name can be any National Language
      *> library, without the suffixed two-digit language code that is
      *> used to determine which message catalog is opened.
      *>
      *> For additonal information, refer to the "National Language
      *> Support (NLS)" chapter in the documentation.
      *>----------------------------------------------------------------

       method-id. "setLanguageLibraryZ".

       local-storage section.
       01 lsLanguageLibrary            usage object reference.

       linkage section.
       01 lnkLanguageLibraryString    pic x.

       procedure division using lnkLanguageLibraryString.
           invoke CharacterArray "withValue"
                           using lnkLanguageLibraryString
                       returning lsLanguageLibrary
           invoke self "setLanguageLibrary"
                           using lsLanguageLibrary
           if lsLanguageLibrary = null
               continue
           else
               invoke lsLanguageLibrary "finalize"
                           returning lsLanguageLibrary
           end-if
           exit method.
       end method "setLanguageLibraryZ".
      *>----------------------------------------------------------------
      *> Get the logical language library name.
      *>
      *> The logical language library name can be any National Language
      *> library, without the suffixed two-digit language code that is
      *> used to determine which message catalog is opened.
      *>
      *> For additonal information, refer to the "National Language
      *> Support (NLS)" chapter in the documentation.
      *>----------------------------------------------------------------

       method-id. "getLanguageLibrary".

       linkage section.
       01 lnkLanguageLibrary       usage object reference.

       procedure division returning lnkLanguageLibrary.
           invoke objLanguageLibrary "copy"
                       returning lnkLanguageLibrary
           exit method.
       end method "getLanguageLibrary".
      *>----------------------------------------------------------------
      *> Get a message (lnkMessage), by specifying the message set
      *> (lnkMessageSet) and the message number (lnkMessageNumber).
      *>
      *> A maximum of six additional insertion parameters
      *> (lnkParameter<n>) may be specified. If used, their character
      *> values will be inserted into the resulting message, using the
      *> National Language File rules and conventions.
      *>----------------------------------------------------------------

       method-id. "getMessage".
       01 utilslbr                        pic x(9) value "utils.lbr".
       local-storage section.
       01 lsLanguageLibraryString          pic x(266).
       01 lsLanguageBasenameString         pic x(266).
       01 lsLanguageExtensionNameString    pic x(266).

       01 lsMessageBlock.
          03 lsMessageSet                  pic x(2) comp-x.
          03 lsMessageNumber               pic x(2) comp-x.
          03 lsMessageMaxBufferLength      pic x(2) comp-x.
          03 lsMessageLength               pic x(2) comp-x.
          03 lsMessageFlags                pic x(2) comp-x.

       01 lsMessageBuffer                  pic x(2048).

       01 lsParameterBlock.
          03 lsParametersUsed              pic x(2) comp-x.
          03 lsParameterPointer            usage pointer occurs 6 times.

       01 lsMessageByteLength              pic s9(9) comp-5.

       01 lsParam1Size                     pic s9(9) comp-5.
       01 lsParam2Size                     pic s9(9) comp-5.
       01 lsParam3Size                     pic s9(9) comp-5.
       01 lsParam4Size                     pic s9(9) comp-5.
       01 lsParam5Size                     pic s9(9) comp-5.
       01 lsParam6Size                     pic s9(9) comp-5.

       01 lsPointer1                       usage pointer.
       01 lsPointer2                       usage pointer.
       01 lsPointer3                       usage pointer.
       01 lsPointer4                       usage pointer.
       01 lsPointer5                       usage pointer.
       01 lsPointer6                       usage pointer.
       01 lsResult                         pic x(4) comp-5.

       linkage section.
       01 lnkMessageSet                    pic x(4) comp-5.
       01 lnkMessageNumber                 pic x(4) comp-5.
       01 lnkParameter1                    usage object reference.
       01 lnkParameter2                    usage object reference.
       01 lnkParameter3                    usage object reference.
       01 lnkParameter4                    usage object reference.
       01 lnkParameter5                    usage object reference.
       01 lnkParameter6                    usage object reference.
       01 lnkMessage                       usage object reference.

       01 lnkParameter1String.
          03 lnkParameter1Char     pic x occurs 0 to maxNumberBytes
                                       depending on lsParam1Size.

       01 lnkParameter2String.
          03 lnkParameter2Char     pic x occurs 0 to maxNumberBytes
                                       depending on lsParam2Size.

       01 lnkParameter3String.
          03 lnkParameter3Char     pic x occurs 0 to maxNumberBytes
                                       depending on lsParam3Size.

       01 lnkParameter4String.
          03 lnkParameter4Char     pic x occurs 0 to maxNumberBytes
                                       depending on lsParam4Size.

       01 lnkParameter5String.
          03 lnkParameter5Char     pic x occurs 0 to maxNumberBytes
                                       depending on lsParam5Size.

       01 lnkParameter6String.
          03 lnkParameter6Char     pic x occurs 0 to maxNumberBytes
                                       depending on lsParam6Size.

       procedure division
                          using lnkMessageSet
                                lnkMessageNumber
                                lnkParameter1
                                lnkParameter2
                                lnkParameter3
                                lnkParameter4
                                lnkParameter5
                                lnkParameter6
                      returning lnkMessage.

           perform before-call
           perform make-call
           perform after-call
           exit method
           .
       before-call section.
           move spaces to lsLanguageLibraryString
           invoke objLanguageLibrary "getValue"
                       returning lsLanguageLibraryString

           move spaces to lsLanguageBasenameString
           invoke objLanguageBasename "getValue"
                       returning lsLanguageBasenameString

           move spaces to lsLanguageExtensionNameString
           invoke objLanguageExtensionName "getValue"
                       returning lsLanguageExtensionNameString

           move lnkMessageSet to lsMessageSet
           move lnkMessageNumber to lsMessageNumber
           move length of lsMessageBuffer to lsMessageMaxBufferLength
           move zero to lsMessageLength
           move spaces to lsMessageBuffer
           move zero to lsParametersUsed

           if address of lnkParameter1 not = null
               if lnkParameter1 not = null
                   add 1 to lsParametersUsed
                   invoke lnkParameter1 "sizeInBytes"
                               returning lsParam1Size
                   add 1 to lsParam1Size
                   invoke self "malloc"
                                   using lsParam1Size
                               returning lsPointer1
                   set address of lnkParameter1String to lsPointer1
                   invoke lnkParameter1 "getValue"
                               returning lnkParameter1String
                   move x"00" to lnkParameter1String(lsParam1Size:1)
                   set lsParameterPointer(lsParametersUsed) to
                       lsPointer1
               end-if
           if address of lnkParameter2 not = null
               if lnkParameter2 not = null
                   add 1 to lsParametersUsed
                   invoke lnkParameter2 "sizeInBytes"
                               returning lsParam2Size
                   add 1 to lsParam2Size
                   invoke self "malloc"
                                   using lsParam2Size
                               returning lsPointer2
                   set address of lnkParameter2String to lsPointer2
                   invoke lnkParameter2 "getValue"
                               returning lnkParameter2String
                   move x"00" to lnkParameter2String(lsParam2Size:1)
                   set lsParameterPointer(lsParametersUsed) to
                       lsPointer2
               end-if
           if address of lnkParameter3 not = null
               if lnkParameter3 not = null
                   add 1 to lsParametersUsed
                   invoke lnkParameter3 "sizeInBytes"
                               returning lsParam3Size
                   add 1 to lsParam3Size
                   invoke self "malloc"
                                   using lsParam3Size
                               returning lsPointer3
                   set address of lnkParameter3String to lsPointer3
                   invoke lnkParameter3 "getValue"
                               returning lnkParameter3String
                   move x"00" to lnkParameter3String(lsParam3Size:1)
                   set lsParameterPointer(lsParametersUsed) to
                       lsPointer3
               end-if
           if address of lnkParameter4 not = null
               if lnkParameter4 not = null
                   add 1 to lsParametersUsed
                   invoke lnkParameter4 "sizeInBytes"
                               returning lsParam4Size
                   add 1 to lsParam4Size
                   invoke self "malloc"
                                   using lsParam4Size
                               returning lsPointer4
                   set address of lnkParameter4String to lsPointer4
                   invoke lnkParameter4 "getValue"
                               returning lnkParameter4String
                   move x"00" to lnkParameter4String(lsParam4Size:1)
                   set lsParameterPointer(lsParametersUsed) to
                       lsPointer4
               end-if
           if address of lnkParameter5 not = null
               if lnkParameter5 not = null
                   add 1 to lsParametersUsed
                   invoke lnkParameter5 "sizeInBytes"
                               returning lsParam5Size
                   add 1 to lsParam5Size
                   invoke self "malloc"
                                   using lsParam5Size
                               returning lsPointer5
                   set address of lnkParameter5String to lsPointer5
                   invoke lnkParameter5 "getValue"
                               returning lnkParameter5String
                   move x"00" to lnkParameter5String(lsParam5Size:1)
                   set lsParameterPointer(lsParametersUsed) to
                       lsPointer5
               end-if
           if address of lnkParameter6 not = null
               if lnkParameter6 not = null
                   add 1 to lsParametersUsed
                   invoke lnkParameter6 "sizeInBytes"
                               returning lsParam6Size
                   add 1 to lsParam6Size
                   invoke self "malloc"
                                   using lsParam6Size
                               returning lsPointer6
                   set address of lnkParameter6String to lsPointer6
                   invoke lnkParameter6 "getValue"
                               returning lnkParameter6String
                   move x"00" to lnkParameter6String(lsParam6Size:1)
                   set lsParameterPointer(lsParametersUsed) to
                       lsPointer6
               end-if
           end-if
           end-if
           end-if
           end-if
           end-if
           end-if

           if lsParametersUsed = zero
               move zero to lsMessageFlags
           else
               move 1 to lsMessageFlags
           end-if

           .

       make-call section.

           call utilslbr
           on exception
               continue
           end-call
           call "CBL_NLS_GET_MSG"
                           using lsLanguageLibraryString
                                 lsLanguageBasenameString
                                 lsLanguageExtensionNameString
                                 lsMessageBlock
                                 lsMessageBuffer
                                 lsParameterBlock
                        returning lsResult
           on exception
               call utilslbr
               call "CBL_NLS_GET_MSG"
                           using lsLanguageLibraryString
                                 lsLanguageBasenameString
                                 lsLanguageExtensionNameString
                                 lsMessageBlock
                                 lsMessageBuffer
                                 lsParameterBlock
                        returning lsResult
           end-call
           .

       after-call section.
           if address of lnkParameter1 not = null
               if lnkParameter1 not = null
                   invoke self "dealloc"
                               using lsPointer1
               end-if
           if address of lnkParameter2 not = null
               if lnkParameter2 not = null
                   invoke self "dealloc"
                               using lsPointer2
               end-if
           if address of lnkParameter3 not = null
               if lnkParameter3 not = null
                   invoke self "dealloc"
                               using lsPointer3
               end-if
           if address of lnkParameter4 not = null
               if lnkParameter4 not = null
                   invoke self "dealloc"
                               using lsPointer4
               end-if
           if address of lnkParameter5 not = null
               if lnkParameter5 not = null
                   invoke self "dealloc"
                               using lsPointer5
               end-if
           if address of lnkParameter6 not = null
               if lnkParameter6 not = null
                   invoke self "dealloc"
                               using lsPointer6
               end-if
           end-if
           end-if
           end-if
           end-if
           end-if
           end-if

      *>>============================================================<<*
      *>> Create a Character Array String to hold the message. The   *<<
      *>> object reference value will then be returned to the caller *<<
      *>>============================================================<<*
           if lsResult = zero
               invoke characterArray "withValue"
                               using lsMessageBuffer
                           returning lnkMessage
      *>>===================================================<<*
      *>> Create a null string if a problem is encountered. <<*
      *>>===================================================<<*
           else
               move zero to lsMessageByteLength
               invoke characterArray "new"
                               using lsMessageByteLength
                           returning lnkMessage
           end-if
       end method "getMessage".
      *>----------------------------------------------------------------
      *> Destroys the MessageFileHandler instance.
      *>----------------------------------------------------------------

       method-id. "finalize".

       linkage section.
       01 lnkOldObject             usage object reference.

       procedure division returning lnkOldObject.
           if objLanguageLibrary = null
               continue
           else
               invoke objLanguageLibrary "finalize"
                           returning objLanguageLibrary
           end-if
           if objLanguageBasename = null
               continue
           else
               invoke objLanguageBasename "finalize"
                           returning objLanguageBasename
           end-if
           if objLanguageExtensionName = null
               continue
           else
               invoke objLanguageExtensionName "finalize"
                           returning objLanguageExtensionName
           end-if
           invoke super "finalize"
                       returning lnkOldObject
           exit method.
       end method "finalize".
       end object.
       end class MessageFileHandler.
