      *>----------------------------------------------------------------
      *> A Filename instance represents an operating system filename,
      *> and includes methods to set and get the file path and extension
      *> separately from the name.
      *>
      *> You can also create a collection of filename instances,
      *> representing all the files that match a file specification
      *> which includes wildcards, by using the "expandWildcards"
      *> method.
      *>
      *> Copyright (C) 1991-1999 Micro Focus International Ltd.
      *>
      *>----------------------------------------------------------------
      $set  mfoo
       class-id. Filename data is protected
               inherits from base with data.


        object section.
        class-control.
           Base is class "base"
           OrderedCollection is class "ordrdcll"
           CharacterArray is class "chararry"
           Filename is class "filename".

       working-storage section.


       class-object.

       object-storage section.

      *>----------------------------------------------------------------
      *> Takes a characterarray as the parameter to create a filename.
      *>----------------------------------------------------------------
       method-id. "withName".
       linkage section.
       01 lnkFilename      usage object reference.
       01 lnkCharArray     usage object reference.

       procedure division using lnkCharArray returning lnkFilename.
           invoke super "new" returning lnkFileName
           invoke lnkFilename "initialize" using lnkCharArray
           exit method.
       end method "withName".

      *>----------------------------------------------------------------
      *> Takes a null terminated pic x as the parameter to create a
      *> filename.
      *>----------------------------------------------------------------
       method-id. "withValue".
       local-storage section.
       01 lsCharArray      usage object reference.

       linkage section.
       01 lnkFilename      usage object reference.
       01 lnkChars         pic x.

       procedure division using lnkChars returning lnkFilename.
           invoke CharacterArray "withValue" using lnkChars
                           returning lsCharArray
           invoke self "withName" using lsCharArray
                       returning lnkFilename
           invoke lsCharArray "finalize" returning lsCharArray
           exit method.
       end method "withValue".

      *>----------------------------------------------------------------
      *> Takes a length and a pic x as the parameters to create a
      *> filename.
      *>----------------------------------------------------------------
       method-id. "withLengthValue".
       local-storage section.
       01 lsCharArray      usage object reference.

       linkage section.
       01 lnkFilename      usage object reference.
       01 lnkLength        pic x(4) comp-5.
       01 lnkChars         pic x.

       procedure division using lnkLength
                                lnkChars
                      returning lnkFilename.
           invoke CharacterArray "withLengthValue"
                               using lnkLength
                                     lnkChars
                           returning lsCharArray
           invoke self "withName" using lsCharArray
                       returning lnkFilename
           invoke lsCharArray "finalize" returning lsCharArray
           exit method.
       end method "withLengthValue".

      *>----------------------------------------------------------------
      *> Takes a buffer length and a pic x as the parameters to create a
      *> filename. Here the filename is calculated by searching the
      *> the buffer backwards trimming extra spaces. This allows
      *> filenames to be created easily from spacey filenames to be
      *> passed.
      *>----------------------------------------------------------------
       method-id. "withBufferLengthValue".
       local-storage section.
       01 lsCharArray      usage object reference.
       01 lsCharArray2     usage object reference.
       01 lsLength         pic x(4) comp-5.
       linkage section.
       01 lnkFilename      usage object reference.
       01 lnkLength        pic x(4) comp-5.
       01 lnkChars         pic x.

       procedure division using lnkLength
                                lnkChars
                      returning lnkFilename.
           move lnkLength to lsLength
           perform varying lsLength from lsLength by -1
                      until lsLength = 0 or
                            lnkChars(lsLength:1) not = x"00"
           end-perform
           invoke CharacterArray "withByteLengthValue"
                               using lsLength
                                     lnkChars
                           returning lsCharArray
           invoke lsCharArray "trimBlanks" returning lsCharArray2
           invoke lsCharArray "finalize" returning lsCharArray
           invoke self "withName" using lsCharArray2
                       returning lnkFilename
           invoke lsCharArray2 "finalize" returning lsCharArray2
           exit method.
       end method "withBufferLengthValue".

      *>----------------------------------------------------------------
      *> This method takes a filename that may contain wildcards
      *> eg c:\*.* and will return a collection of filenames that
      *> match the file specification.
      *>----------------------------------------------------------------
       method-id. "expandWildcards".
       local-storage section.
       01 i                pic x(4) comp-5.
       01 lsFileName       usage object reference.
       linkage section.
       01 lnkFilename      usage object reference.
       01 lnkCollection    usage object reference.

       procedure division using lnkFileName returning lnkCollection.
           move 50 to i
           invoke OrderedCollection "ofReferences" using i
                       returning lnkCollection

           invoke self "findfirst" using lnkFileName
                       returning lsFileName
           perform until lsFileName = null
               invoke lnkCOllection "add" using lsFileName
               invoke lsFilename "findNext" returning lsFileName
           end-perform
           exit method.
       end method "expandWildcards".

      *>----------------------------------------------------------------
      *> This method takes a filename that may contain wildcards
      *> eg c:\*.* and will return the first filename that matches
      *> this specification.
      *>----------------------------------------------------------------
       method-id. "findFirst".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.
       01 lsChararray2        usage object reference.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).
       01 lsCharArray       usage object reference.
       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       01 lsMask            pic x comp-5.
       01 i                 pic x(4) comp-5.
       01 lsPath            usage object reference.
       01 lsFileSpec        usage object reference.
       01 lsObj             usage object reference.
       01 lsSearchPathSize  pic x(4) comp-5.
       01 lsFilename        usage object reference.

       linkage section.
       01 lnkFileSpec      usage object reference.

       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator
       01 lnkFileName         usage object reference.

       procedure division using lnkFileSpec returning lnkFilename.
           invoke lnkFileSpec "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 0 to f-action      *> Find the first matching file
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke lnkFileSpec "getValue" returning f-filein( 2 : )
           move '" ' to f-filein(lsFileNameSize + 2:2)
           move low-values to f-fileout
           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               perform varying i from 300 by -1 until
                       f-fileout(i:1) not = x"00"
               end-perform
               subtract 1 from i
               invoke CharacterArray "withByteLengthValue"
                       using i f-fileout
                   returning lsCharArray

               invoke self "withName" using lnkFileSpec
                       returning lsFileSpec
               invoke lsFileSpec "path" returning lsPath

               move 16 to lsMask
               call "CBL_AND" using f-attrout
                                    lsMask
                                    by value 1

               if lsMask = 16
                   invoke lsPath "size"
                               returning lsSearchPathSize
                   if lsSearchPathSize = 0
                       invoke lsChararray "concatz" using z"\"
                               returning lsChararray2
                       invoke self "withName" using lsCharArray2
                               returning lnkFileName
                       invoke lsChararray2 "finalize"
                               returning lsChararray2
                   else
                       invoke self "withName"
                                using lsPath
                            returning lnkFileName
                        invoke lnkFileName "appendDir"
                                       using lsCharArray
                    end-if
               else
        	    invoke self "withName" using lsCharArray
	                       returning lnkFileName
		    invoke lnkFileName "setPath" using lsPath
	       end-if
               invoke lnkFileName "setSearchPath" using lsPath
               invoke lnkFileName "setSearchHandle" using f-handle
               if (i = 1 and f-fileout(1:1) = '.') or
                  (i = 2 and f-fileout(1:2) = '..')
	           set lsFilename to lnkFilename
                   invoke lsFilename "findNext" returning lnkFilename
	           invoke lsFilename "finalize" returning lsFilename
               end-if
               invoke lsChararray "finalize"    returning lsChararray
           else
               set lnkFileName to null
           end-if
           exit method.
       end method "findFirst".


       end class-object.


       Object.

       object-storage section.
       01 osFileName       usage object reference.
       01 osSearchHandle   pic x(2) comp-x.
       01 osSearchPath     usage object reference.
       01 oshasExtension     pic x comp-5.
           88 hasExtension    value 1.
           88 DoesNotHaveExtension    value 0.

      *>---------------------------------------------------------------
      *> PRIVATE. Initialize the filename to the character array
      *> lnkCharArray.
      *>----------------------------------------------------------------
       method-id. "initialize".
       local-storage section.
       01 lsExtension    usage object reference.
       01 lsSize         pic x(4) comp-5.
       01 lsBool         pic x comp-5.


       linkage section.
       01 lnkCharArray     usage object reference.
       procedure division using lnkCharArray.
           invoke lnkCharArray "asInternalFilename"
                   returning osFileName
           set hasExtension to true
           invoke self "extension" returning lsExtension
           invoke lsExtension "sizeInBytes" returning lsSize
           if lsSize = 0 or lsExtension = null
               set doesNotHaveExtension to true
           else
               if lsSize = 1
                   invoke lsExtension
                           "equalByLengthValue" using lsSize
                                                        "."
                                     returning lsBool
                   if lsBool = 1
                       set doesNotHaveExtension to true
                   else
                       set HasExtension to true
                   end-if
               else
                   set HasExtension to true
               end-if

           end-if
           invoke lsExtension "finalize" returning lsExtension
           exit method.
       end method "initialize".

      *>---------------------------------------------------------------
      *> Return the path for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> c:\dos\ would be returned.
      *>----------------------------------------------------------------
       method-id. "path".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsResult     pic x(4) comp-5.

       linkage section.
       01 lnkPath               usage object reference.
       01 lnkFilename           pic x.
       procedure division returning lnkPath.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               set address of lnkFilename to lsPtr
               move path-len to lsSize
               invoke CharacterArray "withByteLengthValue" using lsSize
                           lnkFilename(path-strt:)
                       returning lnkPath
           else
               set lnkPath to null
           end-if
           exit method.
       end method "path".

      *>---------------------------------------------------------------
      *> Return the basename for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> fred would be returned.
      *>----------------------------------------------------------------
       method-id. "basename".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsResult     pic x(4) comp-5.

       linkage section.
       01 lnkPath               usage object reference.
       01 lnkFilename           pic x.
       procedure division returning lnkPath.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               if doesNotHaveExtension
                   if extension-len <> 0
                       add extension-len to basename-len
                       add 1 to basename-len *>> For the .
                   end-if
               end-if
               move basename-len to lsSize
               set address of lnkFilename to lsPtr

               invoke CharacterArray "withByteLengthValue" using lsSize
                           lnkFilename(basename-strt:)
                       returning lnkPath
           else
               set lnkPath to null
           end-if
           exit method.
       end method "basename".

      *>---------------------------------------------------------------
      *> Return the extension for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> txt would be returned.
      *>----------------------------------------------------------------
       method-id. "extension".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsResult     pic x(4) comp-5.

       linkage section.
       01 lnkPath               usage object reference.
       01 lnkFilename           pic x.
       procedure division returning lnkPath.
           if hasExtension
              move low-values to splitParamBlock
              move length of splitParamBlock to param-length
              move 2 to splitjoin-flg1
              invoke osFileName "getAddress" returning lsPtr
              invoke osFIleName "sizeInBytes" returning lsSize
              move lsSize to split-buf-len
              call "CBL_SPLIT_FILENAME"
                          using splitParamBlock
                                by value lsPtr
                      returning lsResult
              if lsresult = 0
                  set address of lnkFilename to lsPtr
                  move extension-len to lsSize
                  invoke CharacterArray "withByteLengthValue"
                                      using lsSize
                              lnkFilename(extension-strt:)
                          returning lnkPath
              else
                  set lnkPath to null
              end-if
           else
              invoke CharacterArray "withValue" using x"00"
                   returning lnkPath
           end-if
           exit method.
       end method "extension".

      *>---------------------------------------------------------------
      *> Return the filename for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> fred.txt would be returned.
      *>----------------------------------------------------------------
       method-id. "filenameWithOutDir".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsResult     pic x(4) comp-5.

       linkage section.
       01 lnkPath               usage object reference.
       01 lnkFilename           pic x.
       procedure division returning lnkPath.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               set address of lnkFilename to lsPtr

               move extension-len to lsSize
               add extension-strt to lsSize
               subtract basename-strt from lsSize

               invoke CharacterArray "withByteLengthValue" using lsSize
                           lnkFilename(basename-strt:)
                       returning lnkPath
           else
               set lnkPath to null
           end-if
           exit method.
       end method "filenameWithoutDir".


      *>---------------------------------------------------------------
      *> Return the basename for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> fred would be returned.
      *>----------------------------------------------------------------
       method-id. "fullfilename".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsResult     pic x(4) comp-5.

       linkage section.
       01 lnkPath               usage object reference.
       01 lnkFilename           pic x.
       procedure division returning lnkPath.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               set address of lnkFilename to lsPtr
               move total-length to lsSize
               invoke CharacterArray "withByteLengthValue" using lsSize
                           lnkFilename(path-strt:)
                       returning lnkPath
           else
               set lnkPath to null
           end-if
           exit method.
       end method "fullfilename".

      *>---------------------------------------------------------------
      *> Set the path for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> and the new path was c:\windows\ then this filename would
      *> contain c:\windows\fred.txt.
      *>----------------------------------------------------------------
       method-id. "setPath".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsPtr2       usage pointer.
       01 lsPtr3       usage pointer.
       01 lsResult     pic x(4) comp-5.
       01 lsPath       usage object reference.

       linkage section.
       01 lnkPath               usage object reference.
       01 lnkFilename           pic x.
       procedure division using lnkPath.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInbytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               move lsSize to join-buf-len
               invoke lnkPath "asInternalFileName" returning lsPath
               invoke lsPath "sizeInBytes" returning lsSize
               move lsSize to path-len
               add lsSize to join-buf-len
               move join-buf-len to lsSize
               invoke self "malloc" using lsSize
                       returning lsPtr2
               move 1 to path-strt
               invoke lsPath "getAddress" returning lsPtr3
               call "CBL_JOIN_FILENAME"
                       using splitParamBlock
                             by value lsPtr2
                             by value lsPtr3
                             by value lsPtr
                             by value lsPtr
                   returning lsResult
               move total-length to lsSize
               invoke osFilename "finalize" returning osFilename
               invoke CharacterArray "withByteLengthValue" using lsSize
                           by value lsPtr2
                       returning osFilename
               invoke self "dealloc" using lsPtr2
               invoke lsPath "finalize" returning lsPath
           end-if
           exit method.
       end method "setPath".


      *>---------------------------------------------------------------
      *> Set the path for this filename. For example if this
      *> filename contained the filename c:\dos\fred.txt
      *> and the new path was c:\windows\ then this filename would
      *> contain c:\windows\fred.txt.
      *>----------------------------------------------------------------
       method-id. "setPathZ".
       local-storage section.
       01 lsCharArray          usage object reference.

       linkage section.
       01 lnkPath               pic x.
       procedure division using lnkPath.
           invoke CharacterArray "withValue" using lnkPath
                   returning lsCharArray

           invoke self "setPath" using lsCharArray
           invoke lsCharArray "finalize" returning lsCharArray
           exit method.
       end method "setPathZ".



      *>---------------------------------------------------------------
      *> Appends a directory to the current directory. For
      *> example if this filename contained the filename c:\dos\fred.txt
      *> and the directory to be appended was tmp then this filename
      *> would contain c:\windows\tmp\fred.txt.
      *>----------------------------------------------------------------
       method-id. "AppendDir".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsPathSize   pic x(4) comp-5.
       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsPtr2       usage pointer.
       01 lsPtr3       usage pointer.
       01 lsResult     pic x(4) comp-5.
       01 lsPath       usage object reference.
       01 lsDir        usage object reference.

       linkage section.
       01 lnkDir                usage object reference.
       01 lnkPath               pic x.
       01 lnkFilename           pic x.
       procedure division using lnkDir.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               move lsSize to join-buf-len
               invoke self "Path" returning lsPath
               invoke lnkDir "asInternalFileName" returning lsDir
               invoke lsPath "sizeInBytes" returning lsPathSize
               move lsPathSize to path-len
               add lsPathSize to join-buf-len
               invoke lsDir "sizeInBytes" returning lsSize
               add lsSize to path-len
               add lsSize to join-buf-len

               move join-buf-len to lsSize
               invoke self "malloc" using lsSize
                       returning lsPtr2

               move path-len to lsSize
               add 1 to lsSize
               invoke self "malloc" using lsSize
                       returning lsPtr3
               set address of lnkPath to lsPtr3
               invoke lsPath "getValue" returning lnkPath
               invoke lsDir "getValue"
                   returning lnkPath(lsPathSize + 1:)
               add 1 to path-len
               move "\" to lnkPath(path-len : 1)
               move 1 to path-strt
               call "CBL_JOIN_FILENAME"
                       using splitParamBlock
                             by value lsPtr2
                             by value lsPtr3
                             by value lsPtr
                             by value lsPtr
                   returning lsResult
               move total-length to lsSize
               invoke osFilename "finalize" returning osFilename
               invoke CharacterArray "withByteLengthValue" using lsSize
                           by value lsPtr2
                       returning osFilename
               invoke self "dealloc" using lsPtr2
               invoke self "dealloc" using lsPtr3
               invoke lsPath "finalize" returning lsPath
               invoke lsDir "finalize" returning lsDir
           end-if
           exit method.
       end method "AppendDir".

      *>---------------------------------------------------------------
      *> Set the extension for this filename. For example if this
      *> filename contained the filename c:\windows\fred.txt
      *> and the new extension was bak then this filename would
      *> contain c:\windows\fred.bak.
      *>----------------------------------------------------------------
       method-id. "setExtensionZ".
       local-storage section.
       01 lsCharArray              usage object reference.
       linkage section.
       01 lnkExtension          pic x.
       procedure division using lnkExtension.
           invoke CharacterArray "withValue" using lnkExtension
                       returning lsCharArray
           invoke self "setExtension" using lsCharArray
           invoke lsCharArray "finalize" returning lsCharArray
           exit method.
       end method "setExtensionZ".



      *>---------------------------------------------------------------
      *> Set the extension for this filename. For example if this
      *> filename contained the filename c:\windows\fred.txt
      *> and the new extension was bak then this filename would
      *> contain c:\windows\fred.bak.
      *>----------------------------------------------------------------
       method-id. "setExtension".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsPtr2       usage pointer.
       01 lsPtr3       usage pointer.
       01 lsResult     pic x(4) comp-5.
       01 lsExtension           usage object reference.

       linkage section.
       01 lnkExtension          usage object reference.
       01 lnkFilename           pic x.
       procedure division using lnkExtension.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               if doesNotHaveExtension
                   if extension-len <> 0
                       add extension-len to basename-len
                       add 1 to basename-len
                       move zero to extension-strt
                       move zero to extension-len
                   end-if
               end-if
               move lsSize to join-buf-len
               invoke lnkExtension "asInternalFileName"
                           returning lsExtension
               invoke lsExtension "sizeInBytes" returning lsSize
               if lsSize > 0
                   set hasExtension to true
               else
                   set doesnothaveextension to true
               end-if

               move lsSize to extension-len
               add lsSize to join-buf-len

               add 1 to join-buf-len *>> just in case no .
               move join-buf-len to lsSize
               invoke self "malloc" using lsSize
                       returning lsPtr2
               move 1 to extension-strt
               invoke lsExtension "getAddress" returning lsPtr3
               call "CBL_JOIN_FILENAME"
                       using splitParamBlock
                             by value lsPtr2
                             by value lsPtr
                             by value lsPtr
                             by value lsPtr3
                   returning lsResult
               move total-length to lsSize
               invoke osFilename "finalize" returning osFilename
               invoke CharacterArray "withByteLengthValue" using lsSize
                           by value lsPtr2
                       returning osFilename
               invoke self "dealloc" using lsPtr2
               invoke lsExtension "finalize" returning lsExtension
           end-if
           exit method.
       end method "setExtension".


      *>---------------------------------------------------------------
      *> Set the basename for this filename. For example if this
      *> filename contained the filename c:\windows\fred.txt
      *> and the new basename was alfred then this filename would
      *> contain c:\windows\alfred.txt.
      *>----------------------------------------------------------------
       method-id. "setBasenameZ".
       local-storage section.
       01 lsCharArray           usage object reference.

       linkage section.
       01 lnkBaseName           pic x.

       procedure division using lnkBasename.
           invoke CharacterArray "withValue" using lnkBasename
                   returning lsCharArray
           invoke self "setBasename" using lsCharArray
           invoke lsCharArray "finalize" returning lsCharArray
           exit method.
       end method "setBasenameZ".

      *>---------------------------------------------------------------
      *> Set the basename for this filename. For example if this
      *> filename contained the filename c:\windows\fred.txt
      *> and the new basename was alfred then this filename would
      *> contain c:\windows\alfred.txt.
      *>----------------------------------------------------------------
       method-id. "setBasename".
       local-storage section.
       01 splitParamBlock.
           03 param-length         pic x(2) comp-x.
           03 splitjoin-flg1       pic x comp-x.
           03 splitjoin-flg2       pic x comp-x.
           03 path-strt            pic x(2) comp-x.
           03 path-len             pic x(2) comp-x.
           03 basename-strt        pic x(2) comp-x.
           03 basename-len         pic x(2) comp-x.
           03 extension-strt       pic x(2) comp-x.
           03 extension-len        pic x(2) comp-x.
           03 total-length         pic x(2) comp-x.
           03 split-buf-len        pic x(2) comp-x.
           03 join-buf-len         pic x(2) comp-x.
           03 first-path-len       pic x(2) comp-x.

       01 lsSize       pic x(4) comp-5.
       01 lsPtr        usage pointer.
       01 lsPtr2       usage pointer.
       01 lsPtr3       usage pointer.
       01 lsResult     pic x(4) comp-5.
       01 lsBaseName           usage object reference.

       linkage section.
       01 lnkBaseName           usage object reference.
       01 lnkFilename           pic x.
       procedure division using lnkBasename.
           move low-values to splitParamBlock
           move length of splitParamBlock to param-length
           move 2 to splitjoin-flg1
           invoke osFileName "getAddress" returning lsPtr
           invoke osFIleName "sizeInBytes" returning lsSize
           move lsSize to split-buf-len
           call "CBL_SPLIT_FILENAME"
                       using splitParamBlock
                             by value lsPtr
                   returning lsResult
           if lsresult = 0
               move lsSize to join-buf-len
               invoke lnkBaseName "asInternalFileName"
                       returning lsBaseName
               invoke lsBasename "sizeInBytes" returning lsSize
               move lsSize to basename-len
               add lsSize to join-buf-len
               move join-buf-len to lsSize
               invoke self "malloc" using lsSize
                       returning lsPtr2
               move 1 to basename-strt
               invoke lsBaseName "getAddress" returning lsPtr3
               call "CBL_JOIN_FILENAME"
                       using splitParamBlock
                             by value lsPtr2
                             by value lsPtr
                             by value lsPtr3
                             by value lsPtr
                   returning lsResult
               move total-length to lsSize
               invoke osFilename "finalize" returning osFilename
               invoke CharacterArray "withByteLengthValue" using lsSize
                           by value lsPtr2
                       returning osFilename
               invoke self "dealloc" using lsPtr2
               invoke lsBaseName "finalize" returning lsBaseName
           end-if
           exit method.
       end method "setBasename".



      *>----------------------------------------------------------------
      *>
      *>----------------------------------------------------------------
       method-id. "finalize".
       local-storage section.
       linkage section.
       01 lnkObject            usage object reference.

       procedure division returning lnkObject.
           invoke osFileName "finalize" returning osFileName
           invoke osSearchPath "finalize" returning osSearchPath
           invoke super "finalize" returning lnkObject
           exit program.
       end method "finalize".
      *>---------------------------------------------------------------
      *> Returns 1 if this file exists otherwise returns zero.
      *>----------------------------------------------------------------
       method-id. "exists".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).

       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       linkage section.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator

       01 lnkBool             pic x comp-5.

       procedure division returning lnkBool.
           invoke osFileName "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 3 to f-action      *> Find one matching file.
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke osFilename "getValue" returning f-filein( 2 : )
           move '" ' to f-filein(lsFileNameSize + 2:2)

           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               move 1 to lnkBool
           else
               move 0 to lnkBool
           end-if
           invoke self "dealloc" using lsPtr
           exit method.
       end method "exists".

      *>---------------------------------------------------------------
      *> Returns this size of this file in bytes if it exists.
      *> If it does not exist then zero is returned. It is best
      *> to check to see if the file exists before invoking this method.
      *>----------------------------------------------------------------
       method-id. "sizeOfFile".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).

       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       linkage section.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator

       01 lnkSize             pic x(4) comp-5.

       procedure division returning lnkSize.
           invoke osFileName "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 3 to f-action      *> Find one matching file.
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke osFilename "getValue" returning f-filein( 2 : )
           move '" ' to f-filein(lsFileNameSize + 2:2)

           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               move f-size to lnkSize
           else
               move 0 to lnkSize
           end-if
           invoke self "dealloc" using lsPtr
           exit method.
       end method "sizeOfFile".

      *>---------------------------------------------------------------
      *> Is directory returns 1 is this file is a directory otherwise
      *> returns zero.
      *>
      *> If this file does not exist then zero is returned.
      *>----------------------------------------------------------------
       method-id. "IsDirectory".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).

       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       01 lsMask            pic x comp-x.
       linkage section.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator

       01 lnkBool             pic x comp-5.

       procedure division returning lnkBool.
           invoke osFileName "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 3 to f-action      *> Find one matching file.
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke osFilename "getValue" returning f-filein( 2 : )
           *>> Need to remove the last trailing slash if there is
           *>> one otherwise may not find directory
           if f-filein(lsFileNameSize + 1:1) = "\" or
              f-filein(lsFileNameSize + 1:1) = "/"
              subtract 1 from lsFileNameSize
           end-if
           move '" ' to f-filein(lsFileNameSize + 2:2)

           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               move 16 to lsMask
               call "CBL_AND" using f-attrout
                                    lsMask
                                    by value 1
               if lsMask = 16
                   move 1 to lnkBool
               else
                   move 0 to lnkBool
               end-if
           else
               move 0 to lnkBool
           end-if
           invoke self "dealloc" using lsPtr
           exit method.
       end method "isDirectory".

      *>---------------------------------------------------------------
      *> IsHidden returns 1 is this file is hidden otherwise
      *> returns zero.
      *>
      *> If this file does not exist then zero is returned.
      *>----------------------------------------------------------------
       method-id. "IsHidden".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).

       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       01 lsMask            pic x comp-5.
       linkage section.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator

       01 lnkBool             pic x comp-5.

       procedure division returning lnkBool.
           invoke osFileName "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 3 to f-action      *> Find one matching file.
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke osFilename "getValue" returning f-filein( 2 : )
           *>> Need to remove the last trailing slash if there is
           *>> one otherwise may not find directory
           if f-filein(lsFileNameSize + 1:1) = "\" or
              f-filein(lsFileNameSize + 1:1) = "/"
              subtract 1 from lsFileNameSize
           end-if
           move '" ' to f-filein(lsFileNameSize + 2:2)

           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               move 2 to lsMask
               call "CBL_AND" using f-attrout
                                    lsMask
                                    by value 1
               if lsMask = 2
                   move 1 to lnkBool
               else
                   move 0 to lnkBool
               end-if
           else
               move 0 to lnkBool
           end-if
           invoke self "dealloc" using lsPtr
           exit method.
       end method "isHidden".

      *>---------------------------------------------------------------
      *> IsReadOnly returns 1 is this file is read-only otherwise
      *> returns zero.
      *>
      *> If this file does not exist then zero is returned.
      *>----------------------------------------------------------------
       method-id. "IsReadOnly".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).

       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       01 lsMask            pic x comp-5.
       linkage section.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator

       01 lnkBool             pic x comp-5.

       procedure division returning lnkBool.
           invoke osFileName "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 3 to f-action      *> Find one matching file.
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke osFilename "getValue" returning f-filein( 2 : )
           *>> Need to remove the last trailing slash if there is
           *>> one otherwise may not find directory
           if f-filein(lsFileNameSize + 1:1) = "\" or
              f-filein(lsFileNameSize + 1:1) = "/"
              subtract 1 from lsFileNameSize
           end-if
           move '" ' to f-filein(lsFileNameSize + 2:2)

           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               move 1 to lsMask
               call "CBL_AND" using f-attrout
                                    lsMask
                                    by value 1
               if lsMask = 1
                   move 1 to lnkBool
               else
                   move 0 to lnkBool
               end-if
           else
               move 0 to lnkBool
           end-if
           invoke self "dealloc" using lsPtr
           exit method.
       end method "isReadOnly".


      *>---------------------------------------------------------------
      *> IsSystemFile returns 1 is this file is a system file otherwise
      *> returns zero.
      *>
      *> If this file does not exist then zero is returned.
      *>----------------------------------------------------------------
       method-id. "IsSystemFile".
       local-storage section.
       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).

       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       01 lsMask            pic x comp-5.
       linkage section.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
                   *> 2 for quotes 1 for space terminator

       01 lnkBool             pic x comp-5.

       procedure division returning lnkBool.
           invoke osFileName "sizeInBytes" returning lsFilenameSize
           move lsFilenameSize to lsSize
           add length of lnkInfoIn to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr
           set address of lnkInfoIn to lsPtr
           move 3 to f-action      *> Find one matching file.
           move h"FF" to f-attrin
           move '"' to f-filein(1:1)
           invoke osFilename "getValue" returning f-filein( 2 : )
           *>> Need to remove the last trailing slash if there is
           *>> one otherwise may not find directory
           if f-filein(lsFileNameSize + 1:1) = "\" or
              f-filein(lsFileNameSize + 1:1) = "/"
              subtract 1 from lsFileNameSize
           end-if
           move '" ' to f-filein(lsFileNameSize + 2:2)

           move 69 to lsFunctionCode
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               move 4 to lsMask
               call "CBL_AND" using f-attrout
                                    lsMask
                                    by value 1
               if lsMask = 4
                   move 1 to lnkBool
               else
                   move 0 to lnkBool
               end-if
           else
               move 0 to lnkBool
           end-if
           invoke self "dealloc" using lsPtr
           exit method.
       end method "IsSystemFile".

      *>---------------------------------------------------------------
      *> PRIVATE. Set the search handle so can do a findNext and a
      *> terminate search.
      *>----------------------------------------------------------------
       method-id. "setSearchHandle".
       linkage section.
       01 lnkSearchHandle      pic x(2) comp-x.

       procedure division using lnkSearchHandle.
           move lnkSearchHandle to osSearchHandle
           exit method.
       end method "setSearchHandle".

      *>---------------------------------------------------------------
      *> PRIVATE. Set the search path so can do a findNext and set up
      *> correct path.
      *>----------------------------------------------------------------
       method-id. "setSearchPath".
       linkage section.
       01 lnkSearchPath      usage object reference.

       procedure division using lnkSearchPath.
           invoke lnkSearchPath "copy" returning osSearchPath
           exit method.
       end method "setSearchPath".

      *>----------------------------------------------------------------
      *> This method is only valid if this filename object was returned
      *> from a findFirst or a findNext.
      *>----------------------------------------------------------------
       method-id. "findNext".
       local-storage section.
       01 lsChararray2        usage object reference.

       01 lsSize             pic x(4) comp-5.
       01 lsPtr              pointer.

       01 lsResult.
           03 f-error        pic x comp-x.
           03 f-handle       pic x(2) comp-x.
           03 f-attrout      pic x comp-x.
           03 f-time         pic x(2) comp-x.
           03 f-date         pic x(2) comp-x.
           03 f-size         pic x(4) comp-x.
           03 f-fileout      pic x(300).
       01 lsCharArray       usage object reference.
       01 lsFunctionCode    pic x comp-x.
       01 lsFilenameSize    pic x(4) comp-5.
       01 lsMask            pic x comp-5.
       01 i                 pic x(4) comp-5.
       01 lnkInfoIn.
           03 f-action        pic x comp-x.
           03 f-attrin        pic x comp-x.
           03 f-filein        pic x(3).
       01 lsObj             usage object reference.
       01 lsSearchPathSize  pic x(4) comp-5.
       linkage section.
       01 lnkFileSpec      usage object reference.

       01 lnkFileName         usage object reference.

       procedure division returning lnkFilename.
           move 1 to f-action      *> Find the next matching file
           move 69 to lsFunctionCode
           move osSearchHandle to f-handle
           move h"FF" to f-attrin
           move low-values to f-filein f-fileout
           call x"91" using lsResult
                            lsFunctionCode
                            lnkInfoIn
           if f-error = 0
               perform varying i from 300 by -1 until
                       f-fileout(i:1) not = x"00"
               end-perform

               move 16 to lsMask
               call "CBL_AND" using f-attrout
                                    lsMask
                                    by value 1

               subtract 1 from i

               *> . and .. cause problems so do not include them
               *> it is unlikely these are really wanted anyway

               if (i = 1 and f-fileout(1:1) = '.') or
                  (i = 2 and f-fileout(1:2) = '..')
                   invoke self "findNext" returning lnkFilename
               else
                   invoke CharacterArray "withByteLengthValue"
                           using i f-fileout
                       returning lsCharArray
                   if lsMask = 16
                       invoke osSearchPath "size"
                               returning lsSearchPathSize
                       if lsSearchPathSize = 0
                           invoke lsChararray "concatz" using z"\"
                               returning lsChararray2
                           invoke selfclass "withName"
                                   using lsCharArray2
                               returning lnkFileName
                           invoke lsChararray2 "finalize"
                               returning lsChararray2
                       else
                           invoke selfclass "withName"
                                   using osSearchPath
                               returning lnkFileName
                           invoke lnkFileName "appendDir"
                                       using lsCharArray
                       end-if
                   else
                       invoke selfclass "withName" using lsCharArray
                           returning lnkFileName
                       invoke lnkFileName "setPath" using osSearchPath
                   end-if
                   invoke lnkFileName "setSearchHandle" using f-handle
                   invoke lnkFIleName "setSearchPath" using osSearchPath
                   invoke lsChararray "finalize" returning lsChararray
               end-if
           else
               set lnkFileName to null
           end-if
           exit method.
       end method "findNext".

      *>---------------------------------------------------------------
      *> Private return the description for this object.
      *>----------------------------------------------------------------
       method-id. "description".
       linkage section.
       01 lnkObject     usage object reference.

       procedure division returning lnkObject.
           invoke osFileName "description" returning lnkObject
           exit method.
       end method "description".

      *>---------------------------------------------------------------
      *> GetAddress returns the address of the filename.
      *>----------------------------------------------------------------
       method-id. "getAddress".
       linkage section.
       01 lnkPtr    usage object reference.

       procedure division returning lnkPtr.
           invoke osFileName "getAddress" returning lnkPtr
           exit method.
       end method "getAddress".


      *>---------------------------------------------------------------
      *> Return size of filename
      *>----------------------------------------------------------------
       method-id. "size".
       linkage section.
       01 lnkSize    pic x(4) comp-5.

       procedure division returning lnkSize.
           invoke osFileName "size" returning lnkSize
           exit method.
       end method "size".


      *>---------------------------------------------------------------
      *> Return the internal filename.
      *>----------------------------------------------------------------
       method-id. "asInternalFilename".
       linkage section.
       01 lnkFile    usage object reference.

       procedure division returning lnkFile.
           invoke osFileName "copy" returning lnkFile.
           exit method.
       end method "asInternalFilename".

      *>---------------------------------------------------------------
      *> Return size of filename
      *>----------------------------------------------------------------
       method-id. "sizeInBytes".
       linkage section.
       01 lnkSize    pic x(4) comp-5.

       procedure division returning lnkSize.
           invoke osFileName "sizeInBytes" returning lnkSize
           exit method.
       end method "sizeInBytes".


      *>---------------------------------------------------------------
      *> Returns the full filename into a buffer.
      *>----------------------------------------------------------------
       method-id. "getValue".
       linkage section.
       01 lnkValue    pic x.

       procedure division returning lnkValue.
           invoke osFileName "getValue" returning lnkValue
           exit method.
       end method "getValue".


      *>---------------------------------------------------------------
      *> Returns the full filename into a buffer and null terminates
      *> the buffer.
      *>----------------------------------------------------------------
       method-id. "asParameter".
       linkage section.
       01 lnkValue    pic x.

       procedure division returning lnkValue.
           invoke osFileName "asParameter" returning lnkValue
           exit method.
       end method "asParameter".


      *>---------------------------------------------------------------
      *> Returns the full filename into a buffer and null terminates
      *> the buffer.
      *>----------------------------------------------------------------
       method-id. "getValueZ".
       linkage section.
       01 lnkValue    pic x.

       procedure division returning lnkValue.
           invoke osFileName "asParameter" returning lnkValue
           exit method.
       end method "getValueZ".

      *>---------------------------------------------------------------
      *> Returns a copy of this filename.
      *>----------------------------------------------------------------
       method-id. "copy".
       local-storage section.
       01 lsAddress         pointer.

       linkage section.
       01 lnkNewFilename    usage object reference.

       procedure division returning lnkNewFilename.
           invoke osFileName "getAddress" returning lsAddress
           invoke selfclass "withValue" using by value lsAddress
                        returning lnkNewFilename
           exit method.
       end method "copy".



      *>---------------------------------------------------------------
      *> Return 1 if this filename is equal 
      *>----------------------------------------------------------------
       method-id. "equal".
       linkage section.
       01 lnkFilename           usage object reference.
       01 lnkBool               pic x comp-5.

       procedure division using lnkFilename returning lnkBool.
           invoke osFileName "equal" using lnkFilename
                                  returning lnkBool
           exit method.
       end method "equal".

      *>---------------------------------------------------------------
      *> Return 1 if this filename is equal regardless of case.
      *>----------------------------------------------------------------
       method-id. "equalsIgnoreCase".
       linkage section.
       01 lnkFilename           usage object reference.
       01 lnkBool               pic x comp-5.

       procedure division using lnkFilename returning lnkBool.
           invoke osFileName "equalsIgnoreCase" using lnkFilename
                                  returning lnkBool
           exit method.
       end method "equalsIgnoreCase".


      *>----------------------------------------------------------------
      *> Return true if this type of collection contains characters
      *>----------------------------------------------------------------
       method-id. "containsDBCSCharacters".
       linkage section.
       01 lnkbool                pic x comp-5.
           88  lnkistrue          value 1.
           88  lnkisfalse         value 0.
       01 acollection          usage object reference.

       procedure division returning lnkbool.
           invoke osFileName "containsDBCSCharacters"
                           returning lnkBool
           exit method.
       end method "ContainsDBCSCharacters".
      *>----------------------------------------------------------------
      *> Return true if this type of collection contains characters
      *>----------------------------------------------------------------
       method-id. "containsCharacters".
       linkage section.
       01 lnkbool                pic x comp-5.
           88  lnkistrue          value 1.
           88  lnkisfalse         value 0.
       01 acollection          usage object reference.

       procedure division returning lnkbool.
           invoke osFileName "containsCharacters" returning lnkBool
           exit method.
       end method "ContainsCharacters".




      *>----------------------------------------------------------------
      *> This will return a characterArray with the filename wrapped
      *> in quotes.
      *>----------------------------------------------------------------
       method-id. "asExternalFilename".
       local-storage section.
       01 lsPtr            pointer.
       01 lsSize           pic x(4) comp-5.

       linkage section.
       01 lnkFileNameX     pic x(2).
       01 lnkFilename      usage object reference.

       procedure division returning lnkFilename.


           invoke osFileName "sizeInBytes" returning lsSize
           add 2 to lsSize
           invoke self "malloc" using lsSize
                       returning lsPtr

           set address of lnkFileNameX to lsPtr
           move '"' to lnkFileNameX( 1 : 1)
           invoke osFilename "getValue"
                       returning lnkFileNameX( 2 : )

           move '"' to lnkFileNameX(lsSize:1)

           invoke CharacterArray "withByteLengthValue"
                                               using lsSize
                                                     lnkFileNameX
                            returning lnkFilename
           invoke self "dealloc" using lsPtr
           exit program.
       end method "asExternalFilename".
       end object.
       end class Filename.
